mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
Remove tags support from code.
This commit is contained in:
parent
0a95b79eb2
commit
36bdce3084
15 changed files with 11 additions and 640 deletions
|
|
@ -5390,7 +5390,6 @@ class Actions
|
|||
|
||||
$iResultCount = 0;
|
||||
$mResult = array();
|
||||
$aTags = array();
|
||||
|
||||
$oAbp = $this->AddressBookProvider($oAccount);
|
||||
if ($oAbp->IsActive())
|
||||
|
|
@ -5398,8 +5397,6 @@ class Actions
|
|||
$iResultCount = 0;
|
||||
$mResult = $oAbp->GetContacts($oAccount->ParentEmailHelper(),
|
||||
$iOffset, $iLimit, $sSearch, $iResultCount);
|
||||
|
||||
$aTags = $oAbp->GetContactTags($oAccount->ParentEmailHelper());
|
||||
}
|
||||
|
||||
return $this->DefaultResponse(__FUNCTION__, array(
|
||||
|
|
@ -5407,8 +5404,7 @@ class Actions
|
|||
'Limit' => $iLimit,
|
||||
'Count' => $iResultCount,
|
||||
'Search' => $sSearch,
|
||||
'List' => $mResult,
|
||||
'Tags' => $aTags
|
||||
'List' => $mResult
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ class Api
|
|||
if (\RainLoop\Api::Actions()->AddressBookProvider() &&
|
||||
\RainLoop\Api::Actions()->AddressBookProvider()->IsActive())
|
||||
{
|
||||
\RainLoop\Api::Actions()->AddressBookProvider()->DeleteAllContactsAndTags($sEmail);
|
||||
\RainLoop\Api::Actions()->AddressBookProvider()->DeleteAllContacts($sEmail);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -113,9 +113,9 @@ class AddressBook extends \RainLoop\Providers\AbstractProvider
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteAllContactsAndTags($sEmail)
|
||||
public function DeleteAllContacts($sEmail)
|
||||
{
|
||||
return $this->IsActive() ? $this->oDriver->DeleteAllContactsAndTags($sEmail) : false;
|
||||
return $this->IsActive() ? $this->oDriver->DeleteAllContacts($sEmail) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -133,17 +133,6 @@ class AddressBook extends \RainLoop\Providers\AbstractProvider
|
|||
$iOffset, $iLimit, $sSearch, $iResultCount) : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param bool $bCache = true
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetContactTags($sEmail, $bCache = true)
|
||||
{
|
||||
return $this->IsActive() ? $this->oDriver->GetContactTags($sEmail, $bCache) : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param string $mID
|
||||
|
|
|
|||
|
|
@ -34,11 +34,6 @@ class Contact
|
|||
*/
|
||||
public $Properties;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $Tags;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
|
|
@ -66,7 +61,6 @@ class Contact
|
|||
$this->Display = '';
|
||||
$this->Changed = \time();
|
||||
$this->Properties = array();
|
||||
$this->Tags = array();
|
||||
$this->ReadOnly = false;
|
||||
$this->IdPropertyFromSearch = 0;
|
||||
$this->Etag = '';
|
||||
|
|
@ -149,8 +143,6 @@ class Contact
|
|||
{
|
||||
$this->Properties[] = new \RainLoop\Providers\AddressBook\Classes\Property(PropertyType::FULLNAME, $this->Display);
|
||||
}
|
||||
|
||||
$this->Tags = \array_map('trim', $this->Tags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -211,7 +203,7 @@ class Contact
|
|||
$oVCard->VERSION = '3.0';
|
||||
$oVCard->PRODID = '-//RainLoop//'.APP_VERSION.'//EN';
|
||||
|
||||
unset($oVCard->FN, $oVCard->EMAIL, $oVCard->TEL, $oVCard->URL, $oVCard->NICKNAME, $oVCard->CATEGORIES, $oVCard->{'X-RL-TAGS'});
|
||||
unset($oVCard->FN, $oVCard->EMAIL, $oVCard->TEL, $oVCard->URL, $oVCard->NICKNAME);
|
||||
|
||||
$sFirstName = $sLastName = $sMiddleName = $sSuffix = $sPrefix = '';
|
||||
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\AddressBook\Classes\Property */ &$oProperty)
|
||||
|
|
@ -272,11 +264,6 @@ class Contact
|
|||
$oVCard->N = array($sLastName, $sFirstName, $sMiddleName, $sPrefix, $sSuffix);
|
||||
$oVCard->REV = \gmdate('Ymd', $this->Changed).'T'.\gmdate('His', $this->Changed).'Z';
|
||||
|
||||
if (0 < \count($this->Tags))
|
||||
{
|
||||
$oVCard->CATEGORIES = $this->Tags;
|
||||
}
|
||||
|
||||
return (string) $oVCard->serialize();
|
||||
}
|
||||
|
||||
|
|
@ -589,13 +576,6 @@ class Contact
|
|||
}
|
||||
|
||||
$this->Properties = $aProperties;
|
||||
|
||||
if (isset($oVCard->CATEGORIES))
|
||||
{
|
||||
$this->Tags = (array) $oVCard->CATEGORIES->getParts();
|
||||
$this->Tags = \is_array($this->Tags) ? $this->Tags : array();
|
||||
$this->Tags = \array_map('trim', $this->Tags);
|
||||
}
|
||||
}
|
||||
|
||||
$this->UpdateDependentValues();
|
||||
|
|
|
|||
|
|
@ -28,11 +28,6 @@ class PdoAddressBook
|
|||
*/
|
||||
private $sPassword;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $aTagsCache;
|
||||
|
||||
public function __construct($sDsn, $sUser = '', $sPassword = '', $sDsnType = 'mysql')
|
||||
{
|
||||
$this->sDsn = $sDsn;
|
||||
|
|
@ -41,7 +36,6 @@ class PdoAddressBook
|
|||
$this->sDsnType = $sDsnType;
|
||||
|
||||
$this->bExplain = false; // debug
|
||||
$this->aTagsCache = array(); // debug
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -470,14 +464,6 @@ class PdoAddressBook
|
|||
':id_contact' => array($iIdContact, \PDO::PARAM_INT)
|
||||
)
|
||||
);
|
||||
|
||||
// clear previos tags
|
||||
$this->prepareAndExecute(
|
||||
'DELETE FROM rainloop_ab_tags_contacts WHERE id_contact = :id_contact',
|
||||
array(
|
||||
':id_contact' => array($iIdContact, \PDO::PARAM_INT)
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -533,47 +519,6 @@ class PdoAddressBook
|
|||
|
||||
$this->prepareAndExecute($sSql, $aParams, true);
|
||||
}
|
||||
|
||||
$aTags = array();
|
||||
$aContactTags = $this->GetContactTags($sEmail);
|
||||
|
||||
$fFindFunc = function ($sName) use ($aContactTags) {
|
||||
|
||||
$iResult = 0;
|
||||
foreach ($aContactTags as $oItem)
|
||||
{
|
||||
if ($oItem && $oItem->Name === $sName)
|
||||
{
|
||||
$iResult = (int) $oItem->IdContactTag;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $iResult;
|
||||
};
|
||||
|
||||
foreach ($oContact->Tags as $sTagName)
|
||||
{
|
||||
$iTagID = $fFindFunc($sTagName);
|
||||
if (0 >= $iTagID)
|
||||
{
|
||||
$iTagID = $this->CreateTag($sEmail, $sTagName, false);
|
||||
}
|
||||
|
||||
if (\is_int($iTagID) && 0 < $iTagID)
|
||||
{
|
||||
$aTags[] = array(
|
||||
':id_tag' => array($iTagID, \PDO::PARAM_INT),
|
||||
':id_contact' => array($iIdContact, \PDO::PARAM_INT)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 < \count($aTags))
|
||||
{
|
||||
$sSql = 'INSERT INTO rainloop_ab_tags_contacts (id_tag, id_contact) VALUES (:id_tag, :id_contact)';
|
||||
$this->prepareAndExecute($sSql, $aTags, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
|
|
@ -584,51 +529,6 @@ class PdoAddressBook
|
|||
return 0 < $iIdContact;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param string $sName
|
||||
* @param bool $bSyncDb = true
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function CreateTag($sEmail, $sName, $bSyncDb = true)
|
||||
{
|
||||
if ($bSyncDb)
|
||||
{
|
||||
$this->SyncDatabase();
|
||||
}
|
||||
|
||||
$iUserID = $this->getUserId($sEmail);
|
||||
|
||||
$this->aTagsCache = array();
|
||||
|
||||
$mResult = false;
|
||||
try
|
||||
{
|
||||
$sSql = 'INSERT INTO rainloop_ab_tags '.
|
||||
'(id_user, tag_name) VALUES (:id_user, :tag_name)';
|
||||
|
||||
$this->prepareAndExecute($sSql,
|
||||
array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||
':tag_name' => array($sName, \PDO::PARAM_STR)
|
||||
)
|
||||
);
|
||||
|
||||
$sLast = $this->lastInsertId('rainloop_ab_tags', 'id_tag');
|
||||
if (\is_numeric($sLast) && 0 < (int) $sLast)
|
||||
{
|
||||
$mResult = (int) $sLast;
|
||||
}
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
throw $oException;
|
||||
}
|
||||
|
||||
return $mResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param array $aContactIds
|
||||
|
|
@ -677,7 +577,7 @@ class PdoAddressBook
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteAllContactsAndTags($sEmail, $bSyncDb = true)
|
||||
public function DeleteAllContacts($sEmail, $bSyncDb = true)
|
||||
{
|
||||
if ($bSyncDb)
|
||||
{
|
||||
|
|
@ -690,136 +590,10 @@ class PdoAddressBook
|
|||
|
||||
$this->prepareAndExecute('DELETE FROM rainloop_ab_properties WHERE id_user = :id_user', $aParams);
|
||||
$this->prepareAndExecute('DELETE FROM rainloop_ab_contacts WHERE id_user = :id_user', $aParams);
|
||||
$this->prepareAndExecute('DELETE FROM rainloop_ab_tags WHERE id_user = :id_user', $aParams);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param array $aTagsIds
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function DeleteTags($sEmail, $aTagsIds)
|
||||
{
|
||||
$this->SyncDatabase();
|
||||
$iUserID = $this->getUserId($sEmail);
|
||||
|
||||
$aTagsIds = \array_filter($aTagsIds, function (&$mItem) {
|
||||
$mItem = (int) \trim($mItem);
|
||||
return 0 < $mItem;
|
||||
});
|
||||
|
||||
if (0 === \count($aTagsIds))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->aTagsCache = array();
|
||||
|
||||
$sIDs = \implode(',', $aTagsIds);
|
||||
$aParams = array(':id_user' => array($iUserID, \PDO::PARAM_INT));
|
||||
|
||||
$this->prepareAndExecute('DELETE FROM rainloop_pab_tags_contacts WHERE id_tag IN ('.$sIDs.')');
|
||||
$this->prepareAndExecute('DELETE FROM rainloop_pab_tags WHERE id_user = :id_user AND id_tag IN ('.$sIDs.')', $aParams);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param array|\RainLoop\Providers\AddressBook\Classes\Contact $mContactOrContacts
|
||||
*/
|
||||
private function populateContactsByTags($sEmail, &$mContactOrContacts)
|
||||
{
|
||||
$aContacts = array();
|
||||
if ($mContactOrContacts)
|
||||
{
|
||||
$aContacts = is_array($mContactOrContacts) ? $mContactOrContacts : array(&$mContactOrContacts);
|
||||
}
|
||||
|
||||
if (\is_array($aContacts) && 0 < \count($aContacts))
|
||||
{
|
||||
$aIdContacts = array();
|
||||
$aIdTagsContacts = array();
|
||||
|
||||
$aTags = $this->GetContactTags($sEmail);
|
||||
|
||||
if (\is_array($aTags) && 0 < \count($aTags))
|
||||
{
|
||||
foreach ($aContacts as $oItem)
|
||||
{
|
||||
$aIdContacts[$oItem->IdContact] = true;
|
||||
}
|
||||
|
||||
if (0 < \count($aIdContacts))
|
||||
{
|
||||
$sSql = 'SELECT id_tag, id_contact FROM rainloop_ab_tags_contacts WHERE id_contact IN ('.\implode(',', \array_keys($aIdContacts)).')';
|
||||
$oStmt = $this->prepareAndExecute($sSql);
|
||||
|
||||
if ($oStmt)
|
||||
{
|
||||
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
if (\is_array($aFetch) && 0 < \count($aFetch))
|
||||
{
|
||||
foreach ($aFetch as $aItem)
|
||||
{
|
||||
if ($aItem && isset($aItem['id_tag'], $aItem['id_contact']))
|
||||
{
|
||||
$sID = (string) $aItem['id_contact'];
|
||||
if (!isset($aIdTagsContacts[$sID]))
|
||||
{
|
||||
$aIdTagsContacts[$sID] = array();
|
||||
}
|
||||
|
||||
$aIdTagsContacts[$sID][] = (string) $aItem['id_tag'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($aFetch);
|
||||
}
|
||||
|
||||
if (0 < \count($aIdTagsContacts))
|
||||
{
|
||||
$fFindFunc = function ($sID) use ($aTags) {
|
||||
|
||||
foreach ($aTags as $oItem)
|
||||
{
|
||||
if ($oItem && (string) $oItem->IdContactTag === $sID)
|
||||
{
|
||||
return\trim($oItem->Name);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
foreach ($aContacts as &$oItem)
|
||||
{
|
||||
$sID = $oItem ? (string) $oItem->IdContact : '';
|
||||
if (0 < \strlen($sID) && isset($aIdTagsContacts[$sID]) && \is_array($aIdTagsContacts[$sID]))
|
||||
{
|
||||
$aNames = array();
|
||||
foreach ($aIdTagsContacts[$sID] as $sSubID)
|
||||
{
|
||||
$sName = $fFindFunc($sSubID);
|
||||
if (0 < \strlen($sName))
|
||||
{
|
||||
$aNames[] = $sName;
|
||||
}
|
||||
}
|
||||
|
||||
$oItem->Tags = $aNames;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param int $iOffset = 0
|
||||
|
|
@ -1012,62 +786,6 @@ class PdoAddressBook
|
|||
}
|
||||
}
|
||||
|
||||
$this->populateContactsByTags($sEmail, $aResult);
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param bool $bCache = true
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetContactTags($sEmail, $bCache = true)
|
||||
{
|
||||
if ($bCache && isset($this->aTagsCache[$sEmail]))
|
||||
{
|
||||
return $this->aTagsCache[$sEmail];
|
||||
}
|
||||
|
||||
$this->SyncDatabase();
|
||||
|
||||
$iUserID = $this->getUserId($sEmail);
|
||||
|
||||
$sSql = 'SELECT id_tag, id_user, tag_name FROM rainloop_ab_tags WHERE id_user = :id_user ORDER BY tag_name ASC';
|
||||
|
||||
$aParams = array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT)
|
||||
);
|
||||
|
||||
$aResult = array();
|
||||
$oStmt = $this->prepareAndExecute($sSql, $aParams);
|
||||
if ($oStmt)
|
||||
{
|
||||
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
if (\is_array($aFetch) && 0 < \count($aFetch))
|
||||
{
|
||||
foreach ($aFetch as $aItem)
|
||||
{
|
||||
$iIdContactTag = $aItem && isset($aItem['id_tag']) ? (int) $aItem['id_tag'] : 0;
|
||||
if (0 < $iIdContactTag)
|
||||
{
|
||||
$oContactTag = new \RainLoop\Providers\AddressBook\Classes\Tag();
|
||||
|
||||
$oContactTag->IdContactTag = (string) $iIdContactTag;
|
||||
$oContactTag->Name = isset($aItem['tag_name']) ? (string) $aItem['tag_name'] : '';
|
||||
$oContactTag->ReadOnly = $iUserID !== (isset($aItem['id_user']) ? (int) $aItem['id_user'] : 0);
|
||||
|
||||
$aResult[] = $oContactTag;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($bCache)
|
||||
{
|
||||
$this->aTagsCache[$sEmail] = $aResult;
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
|
|
@ -1171,11 +889,6 @@ class PdoAddressBook
|
|||
}
|
||||
}
|
||||
|
||||
if ($oContact)
|
||||
{
|
||||
$this->populateContactsByTags($sEmail, $oContact);
|
||||
}
|
||||
|
||||
return $oContact;
|
||||
}
|
||||
|
||||
|
|
@ -1609,27 +1322,6 @@ CREATE TABLE IF NOT EXISTS rainloop_ab_properties (
|
|||
|
||||
)/*!40000 ENGINE=INNODB *//*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS rainloop_ab_tags (
|
||||
|
||||
id_tag int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
id_user int UNSIGNED NOT NULL,
|
||||
tag_name varchar(255) NOT NULL,
|
||||
|
||||
PRIMARY KEY(id_tag),
|
||||
INDEX id_user_rainloop_ab_tags_index (id_user),
|
||||
INDEX id_user_name_rainloop_ab_tags_index (id_user, tag_name)
|
||||
|
||||
)/*!40000 ENGINE=INNODB *//*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS rainloop_ab_tags_contacts (
|
||||
|
||||
id_tag int UNSIGNED NOT NULL,
|
||||
id_contact bigint UNSIGNED NOT NULL,
|
||||
|
||||
INDEX id_tag_rainloop_ab_tags_contacts_index (id_tag),
|
||||
INDEX id_contact_rainloop_ab_tags_contacts_index (id_contact)
|
||||
|
||||
)/*!40000 ENGINE=INNODB */;
|
||||
MYSQLINITIAL;
|
||||
break;
|
||||
|
||||
|
|
@ -1662,23 +1354,6 @@ CREATE TABLE rainloop_ab_properties (
|
|||
CREATE INDEX id_user_rainloop_ab_properties_index ON rainloop_ab_properties (id_user);
|
||||
CREATE INDEX id_user_id_contact_rainloop_ab_properties_index ON rainloop_ab_properties (id_user, id_contact);
|
||||
|
||||
CREATE TABLE rainloop_ab_tags (
|
||||
id_tag serial PRIMARY KEY,
|
||||
id_user integer NOT NULL,
|
||||
tag_name varchar(255) NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX id_user_rainloop_ab_tags_index ON rainloop_ab_tags (id_user);
|
||||
CREATE INDEX id_user_name_rainloop_ab_tags_index ON rainloop_ab_tags (id_user, tag_name);
|
||||
|
||||
CREATE TABLE rainloop_ab_tags_contacts (
|
||||
id_tag integer NOT NULL,
|
||||
id_contact integer NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX id_tag_rainloop_ab_tags_index ON rainloop_ab_tags_contacts (id_tag);
|
||||
CREATE INDEX id_contact_rainloop_ab_tags_index ON rainloop_ab_tags_contacts (id_contact);
|
||||
|
||||
POSTGRESINITIAL;
|
||||
break;
|
||||
|
||||
|
|
@ -1711,23 +1386,6 @@ CREATE TABLE rainloop_ab_properties (
|
|||
CREATE INDEX id_user_rainloop_ab_properties_index ON rainloop_ab_properties (id_user);
|
||||
CREATE INDEX id_user_id_contact_rainloop_ab_properties_index ON rainloop_ab_properties (id_user, id_contact);
|
||||
|
||||
CREATE TABLE rainloop_ab_tags (
|
||||
id_tag integer NOT NULL PRIMARY KEY,
|
||||
id_user integer NOT NULL,
|
||||
tag_name text NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX id_user_rainloop_ab_tags_index ON rainloop_ab_tags (id_user);
|
||||
CREATE INDEX id_user_name_rainloop_ab_tags_index ON rainloop_ab_tags (id_user, tag_name);
|
||||
|
||||
CREATE TABLE rainloop_ab_tags_contacts (
|
||||
id_tag integer NOT NULL,
|
||||
id_contact integer NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX id_tag_rainloop_ab_tags_index ON rainloop_ab_tags_contacts (id_tag);
|
||||
CREATE INDEX id_contact_rainloop_ab_tags_index ON rainloop_ab_tags_contacts (id_contact);
|
||||
|
||||
SQLITEINITIAL;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue