public function delete($pb_delete_related = false, $pa_options = null, $pa_fields = null, $pa_table_list = null) { // nuke related representations foreach ($this->getRepresentations() as $va_rep) { // check if representation is in use anywhere else $qr_res = $this->getDb()->query("SELECT count(*) c FROM ca_objects_x_object_representations WHERE object_id <> ? AND representation_id = ?", (int) $this->getPrimaryKey(), (int) $va_rep["representation_id"]); if ($qr_res->nextRow() && $qr_res->get('c') == 0) { $this->removeRepresentation($va_rep["representation_id"], array('dontCheckPrimaryValue' => true)); } } return parent::delete($pb_delete_related, $pa_options, $pa_fields, $pa_table_list); }
/** * */ 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 (!$this->inTransaction()) { $o_trans = new Transaction($this->getDb()); $this->setTransaction($o_trans); } if (!is_array($pa_options)) { $pa_options = array(); } $vn_id = $this->getPrimaryKey(); if (parent::delete($pb_delete_related, $pa_options, $pa_fields, $pa_table_list)) { // Delete any associated attribute values that use this list item if (!($qr_res = $this->getDb()->query("\n\t\t\t\tDELETE FROM ca_attribute_values \n\t\t\t\tWHERE item_id = ?\n\t\t\t", (int) $vn_id))) { $this->errors = $this->getDb()->errors(); if ($o_trans) { $o_trans->rollback(); } if ($vb_web_set_change_log_unit_id) { BaseModel::unsetChangeLogUnitID(); } return false; } // Kill any attributes that no longer have values // This cleans up attributes that had a single list value (and now have nothing) // in a relatively efficient way // // We should not need to reindex for search here because the delete of the list item itself // should have triggered reindexing // if (!($qr_res = $this->getDb()->query("\n\t\t\t\tDELETE FROM ca_attributes WHERE attribute_id not in (SELECT distinct attribute_id FROM ca_attribute_values)\n\t\t\t"))) { $this->errors = $this->getDb()->errors(); if ($o_trans) { $o_trans->rollback(); } if ($vb_web_set_change_log_unit_id) { BaseModel::unsetChangeLogUnitID(); } return false; } if ($o_trans) { $o_trans->commit(); } if ($vb_web_set_change_log_unit_id) { BaseModel::unsetChangeLogUnitID(); } return true; } if ($o_trans) { $o_trans->rollback(); } if ($vb_web_set_change_log_unit_id) { BaseModel::unsetChangeLogUnitID(); } return false; }