protected function checkFile()
 {
     $filePaths = array('elements/' . $this->type . 's/' . $this->file);
     if (!empty($this->category)) {
         $categories = $this->config->getCategories();
         $categoryPath = '/' . str_replace(' ', '_', strtolower(implode('/', $categories[$this->category]->getParents()))) . '/';
         $filePaths[] = 'elements/' . $this->type . 's' . $categoryPath . $this->file;
     }
     $file = $this->config->getPackagePath();
     $file .= '/core/components/' . $this->config->getLowCaseName() . '/';
     $exists = false;
     foreach ($filePaths as $filePath) {
         $finalFile = $file . $filePath;
         if (file_exists($finalFile)) {
             $exists = $filePath;
             break;
         }
     }
     if ($exists === false) {
         $this->config->error->addError('Elements: ' . $finalFile . ' - file does not exists', true);
         return false;
     }
     $this->filePath = $exists;
     return true;
 }
 /**
  * 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;
     }
 }
 /**
  * @param $parent
  * @return GitPackageConfigCategory[]
  */
 private function getCategoriesForParent($parent)
 {
     $categories = array();
     $allCategories = $this->config->getCategories();
     foreach ($allCategories as $category) {
         if ($category->getParent() == $parent) {
             $categories[] = $category;
         }
     }
     return $categories;
 }
 private function updateCategories(&$notUsedCategories)
 {
     $notUsedCategories = array_keys($this->oldConfig->getCategories());
     $notUsedCategories = array_flip($notUsedCategories);
     /** @var GitPackageConfigCategory[] $categories */
     $categories = $this->newConfig->getCategories();
     foreach ($categories as $name => $category) {
         $catId = $this->modx->gitpackagemanagement->findCategory($category->getParents(), $this->category->id);
         /** @var modCategory $categoryObject */
         $categoryObject = $this->modx->getObject('modCategory', $catId);
         if (!$categoryObject) {
             $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[$name] = $categoryObject->id;
         if (isset($notUsedCategories[$name])) {
             unset($notUsedCategories[$name]);
         }
     }
     return true;
 }