|
|
@@ -15,7 +15,10 @@ class BxDolObjectQuery extends BxDolDb
|
|
|
protected $_oModule;
|
|
|
|
|
|
protected $_sTable;
|
|
|
+
|
|
|
protected $_sTableTrack;
|
|
|
+ protected $_sTableTrackFieldAuthor;
|
|
|
+
|
|
|
protected $_sTriggerTable;
|
|
|
protected $_sTriggerFieldId;
|
|
|
protected $_sTriggerFieldAuthor;
|
|
|
@@ -31,7 +34,10 @@ class BxDolObjectQuery extends BxDolDb
|
|
|
|
|
|
$aSystem = $this->_oModule->getSystemInfo();
|
|
|
$this->_sTable = isset($aSystem['table_main']) ? $aSystem['table_main'] : '';
|
|
|
+
|
|
|
$this->_sTableTrack = isset($aSystem['table_track']) ? $aSystem['table_track'] : '';
|
|
|
+ $this->_sTableTrackFieldAuthor = 'author_id';
|
|
|
+
|
|
|
$this->_sTriggerTable = isset($aSystem['trigger_table']) ? $aSystem['trigger_table'] : '';
|
|
|
$this->_sTriggerFieldId = isset($aSystem['trigger_field_id']) ? $aSystem['trigger_field_id'] : '';
|
|
|
$this->_sTriggerFieldAuthor = isset($aSystem['trigger_field_author']) ? $aSystem['trigger_field_author'] : '';
|
|
|
@@ -82,17 +88,44 @@ class BxDolObjectQuery extends BxDolDb
|
|
|
public function deleteObjectEntries($iObjectId)
|
|
|
{
|
|
|
if(!empty($this->_sTable)) {
|
|
|
- $sQuery = $this->prepare("DELETE FROM {$this->_sTable} WHERE `object_id` = ?", $iObjectId);
|
|
|
+ $sQuery = $this->prepare("DELETE FROM `{$this->_sTable}` WHERE `object_id` = ?", $iObjectId);
|
|
|
if($this->query($sQuery))
|
|
|
- $this->query("OPTIMIZE TABLE {$this->_sTable}");
|
|
|
+ $this->query("OPTIMIZE TABLE `{$this->_sTable}`");
|
|
|
}
|
|
|
|
|
|
if(!empty($this->_sTableTrack)) {
|
|
|
- $sQuery = $this->prepare("DELETE FROM {$this->_sTableTrack} WHERE `object_id` = ?", $iObjectId);
|
|
|
+ $sQuery = $this->prepare("DELETE FROM `{$this->_sTableTrack}` WHERE `object_id` = ?", $iObjectId);
|
|
|
if($this->query($sQuery))
|
|
|
- $this->query ("OPTIMIZE TABLE {$this->_sTableTrack}");
|
|
|
+ $this->query ("OPTIMIZE TABLE `{$this->_sTableTrack}`");
|
|
|
}
|
|
|
}
|
|
|
+ public function deleteAuthorEntries($iAuthorId)
|
|
|
+ {
|
|
|
+ if(empty($this->_sTableTrack))
|
|
|
+ return;
|
|
|
+
|
|
|
+ $bTable = !empty($this->_sTable);
|
|
|
+ $bTableTrigger = !empty($this->_sTriggerTable) && !empty($this->_sTriggerFieldCount);
|
|
|
+
|
|
|
+ if($bTable || $bTableTrigger) {
|
|
|
+ $aTracks = $this->getAll("SELECT * FROM `{$this->_sTableTrack}` WHERE `{$this->_sTableTrackFieldAuthor}`=:author_id", array('author_id' => $iAuthorId));
|
|
|
+ foreach($aTracks as $aTrack) {
|
|
|
+ if($bTable)
|
|
|
+ $this->_deleteAuthorEntriesTableMain($aTrack);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Note. It's essential that Trigger Table is updated at the end,
|
|
|
+ * because it may require updated data from main ($this->_sTable) table.
|
|
|
+ */
|
|
|
+ if($bTableTrigger)
|
|
|
+ $this->_deleteAuthorEntriesTableTrigger($aTrack);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $sQuery = $this->prepare("DELETE FROM `{$this->_sTableTrack}` WHERE `{$this->_sTableTrackFieldAuthor}`=?", $iAuthorId);
|
|
|
+ if($this->query($sQuery))
|
|
|
+ $this->query("OPTIMIZE TABLE `{$this->_sTableTrack}`");
|
|
|
+ }
|
|
|
|
|
|
public function getObjectAuthorId($iId)
|
|
|
{
|
|
|
@@ -109,6 +142,12 @@ class BxDolObjectQuery extends BxDolDb
|
|
|
return (int)$this->getOne($sQuery);
|
|
|
}
|
|
|
|
|
|
+ public function updateMainTableValue($iObjectId, $iValue)
|
|
|
+ {
|
|
|
+ $sQuery = $this->prepare("UPDATE `{$this->_sTable}` SET `count` = `count` + ? WHERE `object_id` = ?", (int)$iValue, $iObjectId);
|
|
|
+ return (int)$this->query($sQuery) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
public function updateTriggerTable($iObjectId)
|
|
|
{
|
|
|
if(empty($this->_sMethodGetEntry))
|
|
|
@@ -132,6 +171,16 @@ class BxDolObjectQuery extends BxDolDb
|
|
|
$sQuery = $this->prepare("UPDATE `{$this->_sTriggerTable}` SET `{$this->_sTriggerFieldCount}` = ? WHERE `{$this->_sTriggerFieldId}` = ?", $aEntry['count'], $iObjectId);
|
|
|
return (int)$this->query($sQuery) > 0;
|
|
|
}
|
|
|
+
|
|
|
+ protected function _deleteAuthorEntriesTableMain($aTrack)
|
|
|
+ {
|
|
|
+ return $this->updateMainTableValue($aTrack['object_id'], -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function _deleteAuthorEntriesTableTrigger($aTrack)
|
|
|
+ {
|
|
|
+ return $this->updateTriggerTableValue($aTrack['object_id'], -1);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/** @} */
|