Exemplo n.º 1
0
 public function deleteOther(ActiveSync_Model_SyncState $_syncState)
 {
     // remove all other synckeys
     $where = array($this->_db->quoteInto('device_id = ?', $_syncState->device_id), $this->_db->quoteInto('type = ?', $_syncState->type), $this->_db->quoteInto('counter != ?', $_syncState->counter));
     $this->_db->delete(SQL_TABLE_PREFIX . 'acsync_synckey', $where);
     return true;
 }
Exemplo n.º 2
0
 public function saveRel(Mage_Admin_Model_Permissions_Rules $rule)
 {
     $this->_write->beginTransaction();
     try {
         $roleId = $rule->getRoleId();
         $this->_write->delete($this->_ruleTable, "role_id = {$roleId}");
         $masterResources = Mage::getModel('admin/permissions_roles')->getResourcesList2D();
         $masterAdmin = false;
         if ($postedResources = $rule->getResources()) {
             foreach ($masterResources as $index => $resName) {
                 if (!$masterAdmin) {
                     $permission = in_array($resName, $postedResources) ? 'allow' : 'deny';
                     $this->_write->insert($this->_ruleTable, array('role_type' => 'G', 'resource_id' => trim($resName, '/'), 'privileges' => '', 'assert_id' => 0, 'role_id' => $roleId, 'permission' => $permission));
                 }
                 if ($resName == 'all' && $permission == 'allow') {
                     $masterAdmin = true;
                 }
             }
         }
         $this->_write->commit();
     } catch (Mage_Core_Exception $e) {
         throw $e;
     } catch (Exception $e) {
         $this->_write->rollBack();
     }
 }
Exemplo n.º 3
0
 public function delete(Mage_Admin_Model_Permissions_Roles $role)
 {
     $this->_write->beginTransaction();
     try {
         $this->_write->delete($this->_roleTable, "role_id={$role->getId()}");
         $this->_write->delete($this->_roleTable, "parent_id={$role->getId()}");
         $this->_write->delete($this->_ruleTable, "role_id={$role->getId()}");
         $this->_write->commit();
     } catch (Mage_Core_Exception $e) {
         throw $e;
     } catch (Exception $e) {
         $this->_write->rollBack();
     }
 }
Exemplo n.º 4
0
 /**
  * Remove um valor do registro
  *
  * @param string $key
  */
 public function __unset($key)
 {
     if (isset($this->{$key})) {
         $this->db->delete("registry", "context='{$this->getContext()}' AND `key`='{$key}'");
         $this->update();
     }
 }
Exemplo n.º 5
0
 /**
  * get array of ids which got send to the client for a given class
  *
  * @param  Syncope_Model_IDevice|string  $_deviceId
  * @param  Syncope_Model_IFolder|string  $_folderId
  * @return Syncope_Model_SyncState
  */
 public function validate($_deviceId, $_folderId, $_syncKey)
 {
     $deviceId = $_deviceId instanceof Syncope_Model_IDevice ? $_deviceId->id : $_deviceId;
     $folderId = $_folderId instanceof Syncope_Model_IFolder ? $_folderId->id : $_folderId;
     $select = $this->_db->select()->from($this->_tablePrefix . 'synckey')->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)->where($this->_db->quoteIdentifier('counter') . ' = ?', $_syncKey)->where($this->_db->quoteIdentifier('type') . ' = ?', $folderId);
     $stmt = $this->_db->query($select);
     $state = $stmt->fetchObject('Syncope_Model_SyncState');
     $stmt = null;
     # see https://bugs.php.net/bug.php?id=44081
     if (!$state instanceof Syncope_Model_ISyncState) {
         return false;
     }
     $this->_convertFields($state);
     // check if this was the latest syncKey
     $select = $this->_db->select()->from($this->_tablePrefix . 'synckey')->where($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId)->where($this->_db->quoteIdentifier('counter') . ' = ?', $_syncKey + 1)->where($this->_db->quoteIdentifier('type') . ' = ?', $folderId);
     $stmt = $this->_db->query($select);
     $moreRecentState = $stmt->fetchObject('Syncope_Model_SyncState');
     $stmt = null;
     # see https://bugs.php.net/bug.php?id=44081
     // found more recent synckey => the last sync repsone got not received by the client
     if ($moreRecentState instanceof Syncope_Model_ISyncState) {
         // undelete entries marked as deleted in syncope_content table
         $this->_db->update($this->_tablePrefix . 'content', array('is_deleted' => 0), array('device_id = ?' => $deviceId, 'folder_id = ?' => $folderId, 'creation_synckey = ?' => $state->counter, 'is_deleted = ?' => 1));
         // remove entries added during latest sync in syncope_content table
         $this->_db->delete($this->_tablePrefix . 'content', array('device_id = ?' => $deviceId, 'folder_id = ?' => $folderId, 'creation_synckey > ?' => $state->counter));
     } else {
         // finaly delete all entries marked for removal in syncope_content table
         $this->_db->delete($this->_tablePrefix . 'content', array('device_id = ?' => $deviceId, 'folder_id = ?' => $folderId, 'is_deleted = ?' => 1));
     }
     // remove all other synckeys
     $this->_deleteOtherStates($state);
     return $state;
 }
Exemplo n.º 6
0
 /**
  * Proxy the call to delete
  *
  * @param  string|object $table
  * @param string $where
  */
 public function delete($table, $where = '')
 {
     if (is_object($table)) {
         $where = 'id = ' . $table->id;
         if ($this->searchService != null) {
             $this->searchService->delete($table);
         }
         if ($this->tagService != null) {
             $this->tagService->deleteTags($table, za()->getUser());
         }
         if ($this->itemLinkService != null) {
             $this->itemLinkService->deleteItem($table);
         }
         $table = get_class($table);
     }
     $table = strtolower($table);
     $return = false;
     try {
         $this->beginTransaction();
         if (is_array($where)) {
             $where = $this->bindValues($where);
         }
         $this->proxied->delete($table, $where);
         $return = true;
         $this->commit();
     } catch (Exception $e) {
         error_log(get_class($e) . " - Caught: " . $e->getMessage());
         error_log($e->getTraceAsString());
         $this->rollBack();
         throw $e;
     }
     return $return;
 }
Exemplo n.º 7
0
 public function removeNode($ID)
 {
     if (!($info = $this->getNodeInfo($ID))) {
         return false;
     }
     if ($ID) {
         $this->_db->beginTransaction();
         try {
             // DELETE FROM my_tree WHERE left_key >= $left_key AND right_key <= $right_key
             $this->_db->delete($this->_table, $this->_left . ' >= ' . $info[$this->_left] . ' AND ' . $this->_right . ' <= ' . $info[$this->_right]);
             // UPDATE my_tree SET left_key = IF(left_key > $left_key, left_key – ($right_key - $left_key + 1), left_key), right_key = right_key – ($right_key - $left_key + 1) WHERE right_key > $right_key
             $sql = 'UPDATE ' . $this->_table . '
                 SET
                     ' . $this->_left . ' = IF(' . $this->_left . ' > ' . $info[$this->_left] . ', ' . $this->_left . ' - ' . ($info[$this->_right] - $info[$this->_left] + 1) . ', ' . $this->_left . '),
                     ' . $this->_right . ' = ' . $this->_right . ' - ' . ($info[$this->_right] - $info[$this->_left] + 1) . '
                 WHERE
                     ' . $this->_right . ' > ' . $info[$this->_right];
             $this->_db->query($sql);
             $this->_db->commit();
             return new Varien_Db_Tree_Node($info, $this->getKeys());
         } catch (Exception $e) {
             $this->_db->rollBack();
             echo $e->getMessage();
         }
     }
 }
 /**
  * Returns true if and only if $value meets the validation requirements
  *
  * If $value fails validation, then this method returns false, and
  * getMessages() will return an array of messages that explain why the
  * validation failed.
  *
  * @param  mixed $value
  * @return boolean
  * @throws \Zend_Valid_Exception If validation of $value is impossible
  */
 public function isValid($value)
 {
     if ($throttleSettings = $this->project->getAskThrottleSettings()) {
         // Prune the database for (very) old attempts
         $where = $this->db->quoteInto('gta_datetime < DATE_SUB(NOW(), INTERVAL ? second)', $throttleSettings['period'] * 20);
         $this->db->delete('gems__token_attempts', $where);
         // Retrieve the number of failed attempts that occurred within the specified window
         $select = $this->db->select();
         $select->from('gems__token_attempts', array(new \Zend_Db_Expr('COUNT(*) AS attempts'), new \Zend_Db_Expr('UNIX_TIMESTAMP(MAX(gta_datetime)) - UNIX_TIMESTAMP() AS last')))->where('gta_datetime > DATE_SUB(NOW(), INTERVAL ? second)', $throttleSettings['period']);
         $attemptData = $this->db->fetchRow($select);
         $remainingDelay = $attemptData['last'] + $throttleSettings['delay'];
         // \MUtil_Echo::track($throttleSettings, $attemptData, $remainingDelay);
         if ($attemptData['attempts'] > $throttleSettings['threshold'] && $remainingDelay > 0) {
             $this->logger->log("Possible token brute force attack, throttling for {$remainingDelay} seconds", \Zend_Log::ERR);
             $this->_messages = $this->translate->_('The server is currently busy, please wait a while and try again.');
             return false;
         }
     }
     // The pure token check
     if ($this->isValidToken($value)) {
         return true;
     }
     $max_length = $this->tracker->getTokenLibrary()->getLength();
     $this->db->insert('gems__token_attempts', array('gta_id_token' => substr($value, 0, $max_length), 'gta_ip_address' => $this->getRequest()->getClientIp()));
     return false;
 }
Exemplo n.º 9
0
 /**
  * reset list of stored id
  *
  * @param Syncope_Model_IDevice|string $_deviceId
  * @param Syncope_Model_IFolder|string $_folderId
  */
 public function resetState($_deviceId, $_folderId)
 {
     $deviceId = $_deviceId instanceof Syncope_Model_IDevice ? $_deviceId->id : $_deviceId;
     $folderId = $_folderId instanceof Syncope_Model_IFolder ? $_folderId->id : $_folderId;
     $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('device_id') . ' = ?', $deviceId), $this->_db->quoteInto($this->_db->quoteIdentifier('folder_id') . ' = ?', $folderId));
     $this->_db->delete($this->_tablePrefix . 'content', $where);
 }
Exemplo n.º 10
0
 /**
  * delete containers, configs and other data of an application
  * 
  * NOTE: if a table with foreign key constraints to applications is added, we need to make sure that the data is deleted here 
  * 
  * @param Tinebase_Model_Application $_applicationName
  * @return void
  */
 public function removeApplicationData(Tinebase_Model_Application $_application)
 {
     $dataToDelete = array('container' => array('tablename' => ''), 'config' => array('tablename' => ''), 'customfield' => array('tablename' => ''), 'rights' => array('tablename' => 'role_rights'), 'definitions' => array('tablename' => 'importexport_definition'), 'filter' => array('tablename' => 'filter'));
     $countMessage = ' Deleted';
     $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('application_id') . '= ?', $_application->getId()));
     foreach ($dataToDelete as $dataType => $info) {
         switch ($dataType) {
             case 'container':
                 $count = Tinebase_Container::getInstance()->deleteContainerByApplicationId($_application->getId());
                 break;
             case 'config':
                 $count = Tinebase_Config::getInstance()->deleteConfigByApplicationId($_application->getId());
                 break;
             case 'customfield':
                 $count = Tinebase_CustomField::getInstance()->deleteCustomFieldsForApplication($_application->getId());
                 break;
             default:
                 if (array_key_exists('tablename', $info) && !empty($info['tablename'])) {
                     $count = $this->_db->delete(SQL_TABLE_PREFIX . $info['tablename'], $where);
                 } else {
                     Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' No tablename defined for ' . $dataType);
                     $count = 0;
                 }
         }
         $countMessage .= ' ' . $count . ' ' . $dataType . '(s) /';
     }
     $countMessage .= ' for application ' . $_application->name;
     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . $countMessage);
 }
 /**
  * Remove the unanswered tokens for inactive rounds.
  *
  * @param \Gems_Tracker_RespondentTrack $respTrack The respondent track to check
  * @param int $userId Id of the user who takes the action (for logging)
  * @return int The number of tokens changed by this code
  */
 protected function removeInactiveRounds(\Gems_Tracker_RespondentTrack $respTrack, $userId)
 {
     $qTrackId = $this->db->quote($this->_trackId);
     $qRespTrackId = $this->db->quote($respTrack->getRespondentTrackId());
     $orgId = $this->db->quote($respTrack->getOrganizationId());
     $where = "gto_start_time IS NULL AND\n            gto_id_respondent_track = {$qRespTrackId} AND\n            gto_id_round != 0 AND\n            gto_id_round IN (SELECT gro_id_round\n                    FROM gems__rounds\n                    WHERE (gro_active = 0 OR gro_organizations NOT LIKE CONCAT('%|',{$orgId},'|%')) AND\n                        gro_id_track = {$qTrackId})";
     return $this->db->delete('gems__tokens', $where);
 }
Exemplo n.º 12
0
 /**
  * Deletes existing rows.
  *
  * @param  array|string $where SQL WHERE clause(s).
  * @return int          The number of rows deleted.
  */
 public function delete($where)
 {
     if (!isset($where)) {
         throw new Exception('condition is null');
     }
     $where = $this->_translateToZendWhere($where);
     return $this->_adapter->delete($this->_tableName, $where);
 }
Exemplo n.º 13
0
 /**
  * Delete row.
  *
  * @return bool Row deleted successfull.
  */
 public function delete(Days_Db_Row $row)
 {
     if (!isset($row->id)) {
         throw new Days_Exception('Not specified `id` for row to delete');
     }
     $where = $this->_db->quoteInto("_{$this->_name}_id=?", $row->id);
     return $this->_db->delete($this->_name, $where) > 0;
 }
 /**
  * remove all relations for application
  *
  * @param string $applicationName
  *
  * @return void
  */
 public function removeApplication($applicationName)
 {
     $tableName = SQL_TABLE_PREFIX . 'relations';
     $select = $this->_db->select()->from($tableName)->columns('rel_id')->where($this->_db->quoteIdentifier('own_model') . ' LIKE ?', $applicationName . '_%');
     $relation_ids = $this->_db->fetchCol($select);
     if (is_array($relation_ids) && count($relation_ids) > 0) {
         $this->_db->delete($tableName, $this->_db->quoteInto($this->_db->quoteIdentifier('rel_id') . ' IN (?)', $relation_ids));
     }
 }
Exemplo n.º 15
0
 private function _migrateFromOldCalendar()
 {
     $db = $this->_db;
     $this->_oldCalId = $db->select()->from('module')->where('name = "Calendar"')->query()->fetchColumn();
     if (!in_array('calendar', $db->listTables()) || empty($this->_oldCalId)) {
         throw new Exception('Old Calendar is gone, cannot migrate');
     }
     $this->_newCalId = $db->select()->from('module')->where('name = "Calendar"')->query()->fetchColumn();
     $this->_db->delete('calendar2');
     $this->_copyEvents();
     $this->_updateSingleChangedOccurrences();
     $this->_updateUsers();
     $this->_updateRights();
     $this->_updateLastEnd();
     $this->_updateTags();
     $this->_updateHistory();
     $this->_regenerateSearch();
 }
Exemplo n.º 16
0
 /**
  *
  * @param array $enumValues
  * @param boolean $reverse
  */
 protected function _alterEnumValues(array $enumValues, $reverse = false)
 {
     foreach ($enumValues as $tableName => $fields) {
         if ($this->_isTableExists($tableName)) {
             $table = $this->_db->describeTable($tableName);
             foreach ($fields as $fieldName => $fieldEnums) {
                 if (!isset($table[$fieldName])) {
                     continue;
                 }
                 preg_match('/^enum\\((.*)\\)$/', $table[$fieldName]['DATA_TYPE'], $matches);
                 foreach (explode(',', $matches[1]) as $value) {
                     $enums[] = trim($value, "'");
                 }
                 $newEnums = $enums;
                 if (isset($fieldEnums['add'])) {
                     if (!$reverse) {
                         foreach ($fieldEnums['add'] as $fieldEnum) {
                             $newEnums[] = $fieldEnum;
                         }
                     } else {
                         foreach ($fieldEnums['add'] as $fieldEnum) {
                             $this->_db->delete($tableName, $fieldName . ' = \'' . $fieldEnum . '\'');
                         }
                         $newEnums = array_diff($newEnums, $fieldEnums['add']);
                     }
                     $newEnums = array_unique($newEnums);
                 }
                 if (isset($fieldEnums['remove'])) {
                     if (!$reverse) {
                         foreach ($fieldEnums['remove'] as $fieldEnum) {
                             $this->_db->delete($tableName, $fieldName . ' = \'' . $fieldEnum . '\'');
                         }
                         $newEnums = array_diff($newEnums, $fieldEnums['remove']);
                     } else {
                         foreach ($fieldEnums['remove'] as $fieldEnum) {
                             $newEnums[] = $fieldEnum;
                         }
                     }
                     $newEnums = array_unique($newEnums);
                 }
                 sort($enums);
                 sort($newEnums);
                 if ($enums != $newEnums) {
                     foreach ($newEnums as &$value) {
                         $value = '\'' . $value . '\'';
                     }
                     $table[$fieldName]['DATA_TYPE'] = 'enum(' . implode(',', $newEnums) . ')';
                     $this->_alterTable($table[$fieldName]);
                 }
             }
         }
     }
 }
Exemplo n.º 17
0
 public function remove($key)
 {
     if (null === $this->_data) {
         $this->_load();
     }
     // Unset in local cache
     unset($this->_data[$key]);
     // Unset in database also
     $this->_database->delete($this->_table, array($this->_map['value'] . ' = ?' => $value));
     // Unset in cache also -_-
     $this->_saveCache();
     return $this;
 }
Exemplo n.º 18
0
 /**
  * Test Adapter's delete() method.
  * Delete one row from test table, and verify it was deleted.
  * Then try to delete a row that doesn't exist, and verify it had no effect.
  *
  * @todo: test that require delimited identifiers.
  */
 public function testDelete()
 {
     $id = $this->getResultSetKey('id');
     $table = $this->getIdentifier(self::TABLE_NAME);
     $result = $this->_db->delete($table, 'id = 2');
     $this->assertEquals(1, $result);
     $select = $this->_db->select()->from($table);
     $result = $this->_db->fetchAll($select);
     $this->assertEquals(1, count($result));
     $this->assertEquals(1, $result[0][$id]);
     $result = $this->_db->delete($table, 'id = 327');
     $this->assertEquals(0, $result);
 }
Exemplo n.º 19
0
 /**
  * Test Adapter's delete() method.
  * Delete one row from test table, and verify it was deleted.
  * Then try to delete a row that doesn't exist, and verify it had no effect.
  *
  * @todo: test that require delimited identifiers.
  */
 public function testDelete()
 {
     $id = $this->getResultSetKey('id');
     $table = $this->getIdentifier(self::TABLE_NAME);
     $result = $this->_db->delete($table, 'id = 2');
     $this->assertEquals(1, $result, 'Expected rows affected to return 1');
     $select = $this->_db->select()->from($table);
     $result = $this->_db->fetchAll($select);
     $this->assertEquals(1, count($result), 'Expected count of result to be 1');
     $this->assertEquals(1, $result[0][$id], 'Expected result[0][id] to be 1');
     $result = $this->_db->delete($table, 'id = 327');
     $this->assertEquals(0, $result, 'Expected rows affected to return 0');
 }
 /**
  * remove all relations for application
  *
  * @param string $applicationName
  *
  * @return void
  */
 public function removeApplication($applicationName)
 {
     $tableName = SQL_TABLE_PREFIX . 'relations';
     $select = $this->_db->select()->from($tableName, array('rel_id'))->where($this->_db->quoteIdentifier('own_model') . ' LIKE ?', $applicationName . '_%')->limit(10000);
     do {
         $relation_ids = $this->_db->fetchCol($select);
         if (is_array($relation_ids) && count($relation_ids) > 0) {
             $this->_db->delete($tableName, $this->_db->quoteInto($this->_db->quoteIdentifier('rel_id') . ' IN (?)', $relation_ids));
         } else {
             break;
         }
     } while (true);
 }
Exemplo n.º 21
0
 /**
  * Delete items from the model
  *
  * @param mixed $filter True to use the stored filter, array to specify a different filter
  * @return int The number of items deleted
  */
 public function delete($filter = true)
 {
     $this->trackUsage();
     $rows = $this->load($filter);
     if ($rows) {
         foreach ($rows as $row) {
             if (isset($row['gro_id_round'])) {
                 $roundId = $row['gro_id_round'];
                 if ($this->isDeleteable($roundId)) {
                     $this->db->delete('gems__rounds', $this->db->quoteInto('gro_id_round = ?', $roundId));
                     // Delete the round before anyone starts using it
                     $this->db->delete('gems__tokens', $this->db->quoteInto('gto_id_round = ?', $roundId));
                 } else {
                     $values['gro_id_round'] = $roundId;
                     $values['gro_active'] = 0;
                     $this->save($values);
                 }
                 $this->addChanged();
             }
         }
     }
 }
 /**
  * Delete items from the model
  *
  * @param mixed $filter True to use the stored filter, array to specify a different filter
  * @return int The number of items deleted
  */
 public function delete($filter = true)
 {
     $rows = $this->load($filter);
     foreach ($rows as $row) {
         $name = $this->getModelNameForRow($row);
         $field = $row['gtf_id_field'];
         if (self::FIELDS_NAME === $name) {
             $this->db->delete('gems__respondent2track2field', $this->db->quoteInto('gr2t2f_id_field = ?', $field));
         } elseif (self::APPOINTMENTS_NAME === $name) {
             $this->db->delete('gems__respondent2track2appointment', $this->db->quoteInto('gr2t2a_id_app_field = ?', $field));
         }
     }
     return parent::delete($filter);
 }
Exemplo n.º 23
0
 /**
  * Delete subscriber from DB
  *
  * @param int $subscriberId
  */
 public function delete($subscriberId)
 {
     if (!(int) $subscriberId) {
         Mage::throwException(Mage::helper('newsletter')->__('Invalid subscriber ID'));
     }
     $this->_write->beginTransaction();
     try {
         $this->_write->delete($this->_subscriberTable, $this->_write->quoteInto('subscriber_id=?', $subscriberId));
         $this->_write->commit();
     } catch (Exception $e) {
         $this->_write->rollBack();
         Mage::throwException(Mage::helper('newsletter')->__('Cannot delete subscriber'));
     }
 }
Exemplo n.º 24
0
 public function delete(Mage_Review_Model_Review $review)
 {
     if ($review->getId()) {
         try {
             $this->_write->beginTransaction();
             $condition = $this->_write->quoteInto('review_id = ?', $review->getId());
             $review->load($review->getId());
             $this->_write->delete($this->_reviewTable, $condition);
             $this->_write->commit();
             $this->aggregate($review);
         } catch (Exception $e) {
             throw new Exception($e->getMessage());
         }
     }
 }
Exemplo n.º 25
0
 /**
  * Deletes existing rows.
  *
  * @param  array|string $where SQL WHERE clause(s).
  * @return int          The number of rows deleted.
  */
 public function delete($where)
 {
     $tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
     /**
      * Run pre-DELETE logic
      */
     if ($this->notify('preDelete', $this, $where) === false) {
         return 0;
     }
     $result = $this->_db->delete($tableSpec, $where);
     /**
      * Run pre-DELETE logic
      */
     $this->notify('preDelete', $this, $where);
     return $result;
 }
Exemplo n.º 26
0
 /**
  * @param Node $node
  * @return $this
  * @throws \Exception
  */
 public function removeNode($node)
 {
     // For reorder old node branch
     $dataReorderOld = [$this->_orderField => new \Zend_Db_Expr($this->_conn->quoteIdentifier($this->_orderField) . '-1')];
     $conditionReorderOld = $this->_conn->quoteIdentifier($this->_parentField) . '=' . $node->getData($this->_parentField) . ' AND ' . $this->_conn->quoteIdentifier($this->_orderField) . '>' . $node->getData($this->_orderField);
     $this->_conn->beginTransaction();
     try {
         $condition = $this->_conn->quoteInto("{$this->_idField}=?", $node->getId());
         $this->_conn->delete($this->_table, $condition);
         // Update old node branch
         $this->_conn->update($this->_table, $dataReorderOld, $conditionReorderOld);
         $this->_conn->commit();
     } catch (\Exception $e) {
         $this->_conn->rollBack();
         throw new \Exception('Can\'t remove tree node');
     }
     parent::removeNode($node);
     return $this;
 }
 /**
  * delete rows by property
  * 
  * @param string|array $_value
  * @param string $_property
  * @param string $_operator (equals|in)
  * @return integer The number of affected rows.
  * @throws Tinebase_Exception_InvalidArgument
  */
 public function deleteByProperty($_value, $_property, $_operator = 'equals')
 {
     $schema = $this->getSchema();
     if (!(isset($schema[$_property]) || array_key_exists($_property, $schema))) {
         throw new Tinebase_Exception_InvalidArgument('Property ' . $_property . ' does not exist in table ' . $this->_tableName);
     }
     switch ($_operator) {
         case 'equals':
             $op = ' = ?';
             break;
         case 'in':
             $op = ' IN (?)';
             $_value = (array) $_value;
             break;
         default:
             throw new Tinebase_Exception_InvalidArgument('Invalid operator: ' . $_operator);
     }
     $where = array($this->_db->quoteInto($this->_db->quoteIdentifier($_property) . $op, $_value));
     return $this->_db->delete($this->_tablePrefix . $this->_tableName, $where);
 }
Exemplo n.º 28
0
 /**
  * Строит поисковый индекс
  * 
  * @param array $options Массив данных для индексирования
  *  
  * @return boolean
  */
 public function buildSearchIndex($options = array())
 {
     $options['indextitle'] = strip_tags($options['indextitle']);
     $options['indextxt'] = strip_tags($options['indextxt']);
     if (preg_match_all('#\\w#u', $options['indextitle'], $title)) {
         $options['indextitle'] = strtoupper(implode(' ', $title[0]));
     }
     if (preg_match_all('#\\w#u', $options['indextxt'], $content)) {
         $options['indextxt'] = strtoupper(implode(' ', $content[0]));
     }
     if (isset($options['resourceid'])) {
         $where = 'resourceid=' . (int) $options['resourceid'];
     } elseif (isset($options['categoryid'])) {
         $where = 'categoryid=' . (int) $options['categoryid'];
     } elseif (isset($options['mvcid'])) {
         $where = 'mvcid=' . (int) $options['mvcid'];
     } else {
         return false;
     }
     $this->_db->delete('pw_search_index', $where);
     $this->_db->insert('pw_search_index', $options);
     return true;
 }
Exemplo n.º 29
0
 /**
  * Deletes existing rows.
  *
  * @param  array|string $where SQL WHERE clause(s).
  * @return int          The number of rows deleted.
  */
 public function delete($where)
 {
     $depTables = $this->getDependentTables();
     if (!empty($depTables)) {
         $resultSet = $this->fetchAll($where);
         if (count($resultSet) > 0) {
             foreach ($resultSet as $row) {
                 /**
                  * Execute cascading deletes against dependent tables
                  */
                 foreach ($depTables as $tableClass) {
                     $t = self::getTableFromString($tableClass, $this);
                     $t->_cascadeDelete($tableClass, $row->getPrimaryKey());
                 }
             }
         }
     }
     $tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
     return $this->_db->delete($tableSpec, $where);
 }
Exemplo n.º 30
0
 /**
  * Deletes existing rows.
  *
  * @param  array|string $where SQL WHERE clause(s).
  * @return int          The number of rows deleted.
  */
 public function delete($where)
 {
     $tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
     return $this->_db->delete($tableSpec, $where);
 }