예제 #1
0
 /**
  * Writes the skins and templates to the database
  *
  * @param $allowOverwrite
  *		set to 1 when allowed to overwrite existing skins with the same name
  *		(default = 0)
  */
 function writeToDatabase($allowOverwrite = 0)
 {
     $existingSkins = $this->checkSkinNameClashes();
     $existingTemplates = $this->checkTemplateNameClashes();
     // if not allowed to overwrite, check if any nameclashes exists
     if (!$allowOverwrite) {
         if (sizeof($existingSkins) > 0 || sizeof($existingTemplates) > 0) {
             return _SKINIE_NAME_CLASHES_DETECTED;
         }
     }
     foreach ($this->skins as $skinName => $data) {
         // 1. if exists: delete all part data, update desc data
         //    if not exists: create desc
         if (in_array($skinName, $existingSkins)) {
             $skinObj = SKIN::createFromName($skinName);
             // delete all parts of the skin
             $skinObj->deleteAllParts();
             // update general info
             $skinObj->updateGeneralInfo($skinName, $data['description'], $data['type'], $data['includeMode'], $data['includePrefix']);
         } else {
             $skinid = SKIN::createNew($skinName, $data['description'], $data['type'], $data['includeMode'], $data['includePrefix']);
             $skinObj = new SKIN($skinid);
         }
         // 2. add parts
         foreach ($data['parts'] as $partName => $partContent) {
             $skinObj->update($partName, $partContent);
         }
     }
     foreach ($this->templates as $templateName => $data) {
         // 1. if exists: delete all part data, update desc data
         //    if not exists: create desc
         if (in_array($templateName, $existingTemplates)) {
             $templateObj = TEMPLATE::createFromName($templateName);
             // delete all parts of the template
             $templateObj->deleteAllParts();
             // update general info
             $templateObj->updateGeneralInfo($templateName, $data['description']);
         } else {
             $templateid = TEMPLATE::createNew($templateName, $data['description']);
             $templateObj = new TEMPLATE($templateid);
         }
         // 2. add parts
         foreach ($data['parts'] as $partName => $partContent) {
             $templateObj->update($partName, $partContent);
         }
     }
 }