if (!$field->hasError()) { if (!$field->setValue("indexable", $_POST["indexable"])) { $cms_message .= "\n" . $cms_language->getMessage(MESSAGE_FORM_ERROR_MALFORMED_FIELD, array($cms_language->getMessage(MESSAGE_PAGE_FIELD_FRONTEND))); } else { //save the data $field->writeToPersistence(); $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_OPERATION_DONE); } } break; case 'deleteObject': if ($object->destroy()) { unset($object); unset($objectID); //unset fields catalog in cache CMS_cache::clearTypeCacheByMetas('atm-polymod-structure', array('type' => 'fields')); $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_OPERATION_DONE); } else { $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_DELETE_OBJECT_ERROR); } break; case "delete": $field = new CMS_poly_object_field($_POST["field"]); if (!$field->hasError() && $field->destroy()) { //then reload object if (sensitiveIO::IsPositiveInteger($objectID)) { $object = new CMS_poly_object_definition($objectID); } $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_OPERATION_DONE); } else { $cms_message .= $cms_language->getMessage(MESSAGE_ACTION_DELETE_FIELD_ERROR);
/** * Destroy this object, in DB and filesystem if needed * Destroy title label also * * @return boolean true on success, false on failure * @access public */ function destroy() { if ($this->_fieldID) { //delete all files of objects for this field $module = CMS_poly_object_catalog::getModuleCodenameForField($this->_fieldID); $filesDir = new CMS_file(PATH_MODULES_FILES_FS . '/' . $module, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY); if ($filesDir->exists()) { //search all files of this field $filesList = $filesDir->getFileList(PATH_MODULES_FILES_FS . '/' . $module . '/*_f' . $this->_fieldID . '_*'); //then delete them foreach ($filesList as $aFile) { if (!CMS_file::deleteFile($aFile['name'])) { $this->raiseError("Can't delete file " . $aFile['name'] . " for field : " . $this->_fieldID); return false; } } } //delete all datas of objects for this field $tables = array('mod_subobject_date_deleted', 'mod_subobject_date_edited', 'mod_subobject_date_public', 'mod_subobject_integer_deleted', 'mod_subobject_integer_edited', 'mod_subobject_integer_public', 'mod_subobject_string_deleted', 'mod_subobject_string_edited', 'mod_subobject_string_public', 'mod_subobject_text_deleted', 'mod_subobject_text_edited', 'mod_subobject_text_public'); foreach ($tables as $aTable) { $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $aTable . "\n\t\t\t\t\twhere\n\t\t\t\t\t\tobjectFieldID = '" . $this->_fieldID . "'\n\t\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table " . $aTable . " for field : " . $this->_fieldID); return false; } } //delete title label object if (sensitiveIO::IsPositiveInteger($this->_objectFieldValues["labelID"])) { $label = new CMS_object_i18nm($this->_objectFieldValues["labelID"]); $label->destroy(); } //delete field DB record $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\tmod_object_field \n\t\t\t\twhere\n\t\t\t\t\tid_mof='" . $this->_fieldID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table mod_object_field for field : " . $this->_fieldID); return false; } //unset fields catalog in cache CMS_cache::clearTypeCache('atm-polymod-structure'); //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => CMS_poly_object_catalog::getModuleCodenameForField($this->_fieldID))); CMS_cache::clearTypeCache('polymod'); } //unset fields catalog in cache CMS_cache::clearTypeCacheByMetas('atm-polymod-structure', array('type' => 'fields')); //finally destroy object instance unset($this); return true; }
/** * Destroy this object in DB * * @return boolean true on success, false on failure * @access public */ function destroy() { if ($this->_ID) { //first delete old polyobject references $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\tmod_object_polyobjects\n\t\t\t\twhere\n\t\t\t\t\tobject_type_id_moo = '" . $this->_ID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table mod_object_polyobjects for object : " . $this->_ID); return false; } //second delete object label and description if (sensitiveIO::IsPositiveInteger($this->getValue("labelID"))) { $label = new CMS_object_i18nm($this->getValue("labelID")); $label->destroy(); } if (sensitiveIO::IsPositiveInteger($this->getValue("descriptionID"))) { $description = new CMS_object_i18nm($this->getValue("labelID")); $description->destroy(); } //third, delete object definition datas $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\tmod_object_definition\n\t\t\t\twhere\n\t\t\t\t\tid_mod = '" . $this->_ID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table mod_object_definition for object : " . $this->_ID); return false; } //unset objects catalog in cache CMS_cache::clearTypeCacheByMetas('atm-polymod-structure', array('type' => 'object')); //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $this->_objectValues["module"])); CMS_cache::clearTypeCache('polymod'); } unset($this); return true; }