private function update()
 {
     //        $vc = version_compare($this->oldConfig->getVersion(), $this->newConfig->getVersion());
     //        if($vc != -1){
     //            return $this->modx->lexicon('gitpackagemanagement.package_err_nvil');
     //        }
     if ($this->oldConfig->getName() != $this->newConfig->getName()) {
         return $this->modx->lexicon('gitpackagemanagement.package_err_ccn');
     }
     if ($this->oldConfig->getLowCaseName() != $this->newConfig->getLowCaseName()) {
         return $this->modx->lexicon('gitpackagemanagement.package_err_ccln');
     }
     $this->object->set('description', $this->newConfig->getDescription());
     $this->object->set('version', $this->newConfig->getVersion());
     /** @var modCategory category */
     $this->category = $this->modx->getObject('modCategory', array('category' => $this->newConfig->getName()));
     if (!$this->category) {
         $this->category = $this->modx->newObject('modCategory');
         $this->category->set('category', $this->newConfig->getName());
         $this->category->save();
     }
     $this->updateDatabase();
     $this->updateActionsAndMenus();
     $this->updateExtensionPackage();
     $this->updateSystemSettings();
     $notUsedCategories = array();
     $this->updateCategories($notUsedCategories);
     $this->updateElements();
     $this->removeNotUsedCategories($notUsedCategories);
     $this->updateResources();
     $this->clearCache();
     return true;
 }
 private function addCategory()
 {
     /** @var modCategory $category */
     $category = $this->modx->newObject('modCategory');
     $category->set('category', $this->config->getName());
     $snippets = $this->getSnippets();
     if (!empty($snippets)) {
         $category->addMany($snippets, 'Snippets');
     }
     $chunks = $this->getChunks();
     if (!empty($chunks)) {
         $category->addMany($chunks, 'Chunks');
     }
     $plugins = $this->getPlugins();
     if (!empty($plugins)) {
         $category->addMany($plugins, 'Plugins');
     }
     $templates = $this->getTemplates();
     if (!empty($templates)) {
         $category->addMany($templates, 'Templates');
     }
     $templateVariables = $this->getTemplateVariables();
     if (!empty($templateVariables)) {
         $category->addMany($templateVariables, 'TemplateVars');
     }
     $categories = $this->getCategories();
     if (!empty($categories)) {
         $category->addMany($categories, 'Children');
     }
     return $this->builder->createVehicle($category, 'category');
 }
 /**
  * Create categories for elements
  */
 private function createCategories()
 {
     $category = $this->modx->getObject('modCategory', array('category' => $this->config->getName()));
     if (!$category) {
         $category = $this->modx->newObject('modCategory');
         $category->set('category', $this->config->getName());
         $category->save();
     }
     $this->category = $category;
     /** @var GitPackageConfigCategory[] $categories */
     $categories = $this->config->getCategories();
     foreach ($categories as $category) {
         $categoryObject = $this->modx->newObject('modCategory');
         $categoryObject->set('category', $category->getName());
         $parent = $category->getParentObject();
         if (!empty($parent)) {
             $catId = $this->modx->gitpackagemanagement->findCategory($parent->getParents(), $this->category->id);
             /** @var modCategory $parentObject */
             $parentObject = $this->modx->getObject('modCategory', $catId);
             if ($parentObject) {
                 $parent = $parentObject->id;
             } else {
                 $parent = $this->category->id;
             }
         } else {
             $parent = $this->category->id;
         }
         $categoryObject->set('parent', $parent);
         $categoryObject->save();
         $this->categoriesMap[$category->getName()] = $categoryObject->id;
     }
 }