Beispiel #1
0
 /**
  * Writes into persistence (MySQL for now), along with base data.
  *
  * @return boolean true on success, false on failure
  * @access public
  */
 function writeToPersistence()
 {
     if (!$this->_uuid) {
         $this->_uuid = io::uuid();
     }
     $isNew = $this->_categoryID === NULL;
     // Inform modules of the object creation
     $modules = CMS_modulesCatalog::getAll('id');
     foreach ($modules as $codename => $module) {
         if (method_exists($module, 'moduleCategoryPreSave')) {
             $module->moduleCategoryPreSave($this, $isNew);
         }
     }
     // Prepare SQL
     $sql_fields = "\n\t\t\tmodule_mca='" . SensitiveIO::sanitizeSQLString($this->_moduleCodename) . "',\n\t\t\troot_mca='" . SensitiveIO::sanitizeSQLString($this->_rootID) . "',\n\t\t\tparent_mca='" . SensitiveIO::sanitizeSQLString($this->_parentID) . "',\n\t\t\torder_mca='" . SensitiveIO::sanitizeSQLString($this->_order) . "',\n\t\t\ticon_mca='" . SensitiveIO::sanitizeSQLString($this->_icon) . "',\n\t\t\tuuid_mca='" . SensitiveIO::sanitizeSQLString($this->_uuid) . "',\n\t\t\tprotected_mca='" . ($this->_protected ? 1 : 0) . "'\n\t\t";
     // Finish SQL
     if ($this->_categoryID) {
         $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tmodulesCategories\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields . "\n\t\t\t\twhere\n\t\t\t\t\tid_mca='" . $this->_categoryID . "'\n\t\t\t";
     } else {
         $sql = "\n\t\t\t\tinsert into\n\t\t\t\t\tmodulesCategories\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields;
     }
     $q = new CMS_query($sql);
     if ($q->hasError()) {
         return false;
     } elseif (!$this->_categoryID) {
         $this->_categoryID = $q->getLastInsertedID();
     }
     //reset catalog info
     CMS_moduleCategories_catalog::getParentIdOf($this->_categoryID, true);
     // Update lineage again with current ID
     $lineage = (string) @implode(';', CMS_moduleCategories_catalog::getLineageOfCategory($this->_categoryID, true));
     if ($this->_lineageFromDB != $lineage) {
         $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tmodulesCategories\n\t\t\t\tset\n\t\t\t\t\tlineage_mca='" . SensitiveIO::sanitizeSQLString($lineage) . "'\n\t\t\t\twhere\n\t\t\t\t\tid_mca='" . $this->_categoryID . "'\n\t\t\t";
         $q = new CMS_query($sql);
         //update siblings lineage if any
         if ($this->hasSiblings()) {
             $siblings = $this->getSiblings();
             foreach ($siblings as $aSibling) {
                 $aSibling->writeToPersistence();
             }
         }
     }
     // Save translations
     // Number of languages availables depends on module
     // instead of languages initially stored into object
     // A way to support easily any new language
     if (is_array($this->_labels) && $this->_labels && $this->_categoryID) {
         $err = 0;
         // Insert each label
         foreach (CMS_languagesCatalog::getAllLanguages($this->_moduleCodename) as $aLanguage) {
             $lang = $aLanguage->getCode();
             // Delete
             $sql = "\n\t\t\t\t\tdelete\n\t\t\t\t\tfrom\n\t\t\t\t\t\tmodulesCategories_i18nm\n\t\t\t\t\twhere\n\t\t\t\t\t\tcategory_mcl='" . $this->_categoryID . "'\n\t\t\t\t\t\tand language_mcl='" . SensitiveIO::sanitizeSQLString($lang) . "'\n\t\t\t\t";
             $qD = new CMS_query($sql);
             if ($qD->hasError()) {
                 $err++;
                 $this->raiseError("Error deleting label in language : `{$lang}`");
             }
             // Insert
             $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\tmodulesCategories_i18nm\n\t\t\t\t\tset\n\t\t\t\t\t\tlanguage_mcl='" . SensitiveIO::sanitizeSQLString($lang) . "',\n\t\t\t\t\t\tcategory_mcl = " . $this->_categoryID . ",\n\t\t\t\t\t\tlabel_mcl='" . SensitiveIO::SanitizeSQLString(@$this->_labels[$lang]) . "',\n\t\t\t\t\t\tdescription_mcl='" . SensitiveIO::SanitizeSQLString(@$this->_descriptions[$lang]) . "',\n\t\t\t\t\t\tfile_mcl='" . SensitiveIO::SanitizeSQLString(@$this->_files[$lang]) . "'\n\t\t\t\t";
             $q = new CMS_query($sql);
             if ($q->hasError()) {
                 $err++;
                 $this->raiseError("Error inserting label in language : `{$lang}`");
             }
         }
         // have to repeat the call here
         $modules = CMS_modulesCatalog::getAll('id');
         foreach ($modules as $codename => $module) {
             if (method_exists($module, 'moduleCategoryPostSave')) {
                 $module->moduleCategoryPostSave($this, $isNew);
             }
         }
         //Clear polymod cache
         //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $this->_moduleCodename));
         CMS_cache::clearTypeCache('polymod');
         return $err <= 0;
     }
     $modules = CMS_modulesCatalog::getAll('id');
     foreach ($modules as $codename => $module) {
         if (method_exists($module, 'moduleCategoryPostSave')) {
             $module->moduleCategoryPostSave($this, $isNew);
         }
     }
     //Clear polymod cache
     //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $this->_moduleCodename));
     CMS_cache::clearTypeCache('polymod');
     return true;
 }