/** * * * @param bool $pb_delete_related * @param array $pa_options * dontCheckPrimaryValue = if set the is_primary state of other related representations is not considered during the delete * @param array $pa_fields * @param array $pa_table_list * * @return bool */ public function delete($pb_delete_related = false, $pa_options = null, $pa_fields = null, $pa_table_list = null) { if (!isset($pa_options['dontCheckPrimaryValue']) && !$pa_options['dontCheckPrimaryValue']) { // make some other row primary $o_db = $this->getDb(); if ($vn_representation_id = $this->getPrimaryKey()) { $qr_res = $o_db->query("\n\t\t\t\t\tSELECT oxor.relation_id\n\t\t\t\t\tFROM ca_objects_x_object_representations oxor\n\t\t\t\t\tINNER JOIN ca_object_representations AS o_r ON o_r.representation_id = oxor.representation_id\n\t\t\t\t\tWHERE\n\t\t\t\t\t\toxor.representation_id = ? AND oxor.is_primary = 1 AND o_r.deleted = 0\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\toxor.rank, oxor.relation_id\n\t\t\t\t", (int) $vn_representation_id); while ($qr_res->nextRow()) { // nope - force this one to be primary $t_rep_link = new ca_objects_x_object_representations(); $t_rep_link->setTransaction($this->getTransaction()); if ($t_rep_link->load($qr_res->get('relation_id'))) { $t_rep_link->setMode(ACCESS_WRITE); $t_rep_link->set('is_primary', 0); $t_rep_link->update(); if ($t_rep_link->numErrors()) { $this->postError(2700, _t('Could not update primary flag for representation: %1', join('; ', $t_rep_link->getErrors())), 'ca_objects_x_object_representations->delete()'); return false; } } else { $this->postError(2700, _t('Could not load object-representation link'), 'ca_objects_x_object_representations->delete()'); return false; } } } } return parent::delete($pb_delete_related, $pa_options, $pa_fields, $pa_table_list); }
/** * Override BaseModel::delete() because the cascading delete implemented there * doesn't properly remove related items if they're organized in a ad-hoc hierarchy. */ public function delete($pb_delete_related = false, $pa_options = null, $pa_fields = null, $pa_table_list = null) { if ($pb_delete_related) { $this->removeAllItems(); } return parent::delete($pb_delete_related, $pa_options, $pa_fields, $pa_table_list); }
/** * Override delete() to scramble the set_code before we soft-delete. This is useful * because the database field has a unique key that really enforces uniqueneness * and we might wanna reuse a code of a set we previously deleted. */ public function delete($pb_delete_related = false, $pa_options = null, $pa_fields = null, $pa_table_list = null) { if ($vn_rc = parent::delete($pb_delete_related, $pa_options, $pa_fields, $pa_table_list)) { if (!caGetOption('hard', $pa_options, false)) { // only applies if we don't hard-delete $vb_we_set_transaction = false; if (!$this->inTransaction()) { $o_t = new Transaction($this->getDb()); $this->setTransaction($o_t); $vb_we_set_transaction = true; } $this->set('set_code', $this->get('set_code') . '_' . time()); $this->update(array('force' => true)); if ($vb_we_set_transaction) { $this->removeTransaction(true); } } } return $vn_rc; }
public function delete($pb_delete_related = false, $pa_options = null, $pa_fields = null, $pa_table_list = null) { $vn_rc = parent::delete($pb_delete_related, $pa_options, $pa_fields, $pa_table_list); if (!$this->numErrors()) { $this->opo_annotations_properties = null; } return $vn_rc; }
/** * Override delete() to scramble the set_code before we soft-delete. This is useful * because the database field has a unique key that really enforces uniqueneness * and we might wanna reuse a code of a set we previously deleted. */ public function delete($pb_delete_related = false, $pa_options = null, $pa_fields = null, $pa_table_list = null) { $vb_web_set_change_log_unit_id = BaseModel::setChangeLogUnitID(); if ($pb_delete_related) { // quickly delete all labels for all set items in this set $this->getDb()->query('DELETE FROM ca_set_item_labels WHERE item_id IN (SELECT item_id FROM ca_set_items WHERE set_id=?)', $this->getPrimaryKey()); // quickly delete attribute values $this->getDb()->query(' DELETE FROM ca_attribute_values WHERE attribute_id IN (SELECT attribute_id FROM ca_attributes WHERE table_num=? and row_id IN (SELECT item_id FROM ca_set_items WHERE set_id=7)) ', $this->tableNum(), $this->getPrimaryKey()); // quickly delete attributes $this->getDb()->query(' DELETE FROM ca_attributes WHERE table_num=? and row_id IN (SELECT item_id FROM ca_set_items WHERE set_id=7) ', $this->tableNum(), $this->getPrimaryKey()); // get list of set item ids $qr_items = $this->getDb()->query('SELECT item_id FROM ca_set_items WHERE set_id=?', $this->getPrimaryKey()); $va_item_ids = $qr_items->getAllFieldValues('item_id'); // nuke set items $this->getDb()->query('DELETE FROM ca_set_items WHERE set_id=?', $this->getPrimaryKey()); // remove search indexing for deleted set items foreach ($va_item_ids as $vn_item_id) { $this->getSearchIndexer()->startRowUnIndexing($this->tableNum(), $vn_item_id); $this->getSearchIndexer()->commitRowUnIndexing($this->tableNum(), $vn_item_id); } } if ($vn_rc = parent::delete($pb_delete_related, $pa_options, $pa_fields, $pa_table_list)) { if (!caGetOption('hard', $pa_options, false)) { // only applies if we don't hard-delete $vb_we_set_transaction = false; if (!$this->inTransaction()) { $o_t = new Transaction($this->getDb()); $this->setTransaction($o_t); $vb_we_set_transaction = true; } $this->set('set_code', $this->get('set_code') . '_' . time()); $this->update(array('force' => true)); if ($vb_we_set_transaction) { $this->removeTransaction(true); } } } if ($vb_web_set_change_log_unit_id) { BaseModel::unsetChangeLogUnitID(); } return $vn_rc; }
/** * */ public function delete($pb_delete_related = false, $pa_options = null, $pa_fields = null, $pa_table_list = null) { $t_left = $this->getAppDatamodel()->getInstanceByTableNum($this->getLeftTableNum()); $vn_left_id = $this->get($this->getLeftTableFieldName()); $vn_right_id = $this->get($this->getRightTableFieldName()); $t_right = $this->getAppDatamodel()->getInstanceByTableNum($this->getRightTableNum()); if ($vn_rc = parent::delete($pb_delete_related, $pa_options, $pa_fields, $pa_table_list)) { foreach (array($this->getRightTableName() => $t_left, $this->getLeftTableName() => $t_right) as $vs_other_table_name => $t_instance) { if ((bool) $t_instance->getProperty('SUPPORTS_ACL_INHERITANCE')) { if (is_array($va_inheritors = $t_instance->getProperty('ACL_INHERITANCE_LIST')) && in_array($vs_other_table_name, $va_inheritors)) { ca_acl::applyACLInheritanceToRelatedRowFromRow($t_instance, $vs_other_table_name == $this->getLeftTableName() ? $vn_right_id : $vn_left_id, $vs_other_table_name, $vs_other_table_name == $this->getLeftTableName() ? $vn_left_id : $vn_right_id, array('deleteACLOnly' => true)); } } } } return $vn_rc; }