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; }
public function beforeSave() { // $url = $this->getProperty('url'); $folderName = $this->getProperty('folderName'); /** * Check if is set packages dir in MODx system settings */ $packagePath = rtrim($this->modx->getOption('gitpackagemanagement.packages_dir', null, null), '/'); if ($packagePath == null) { $this->addFieldError('folderName', $this->modx->lexicon('gitpackagemanagement.package_err_ns_packages_dir')); $this->modx->log(modX::LOG_LEVEL_ERROR, $this->modx->lexicon('gitpackagemanagement.package_err_ns_packages_dir')); $this->modx->log(modX::LOG_LEVEL_INFO, 'COMPLETED'); return false; } $packagePath .= '/'; /** * Check if is filled folder name */ if (empty($folderName)) { $this->addFieldError('folderName', $this->modx->lexicon('gitpackagemanagement.package_err_ns_folder_name')); $this->modx->log(modX::LOG_LEVEL_ERROR, $this->modx->lexicon('gitpackagemanagement.package_err_ns_folder_name')); } /** * Check if build config and core config are writable */ if (!$this->checkConfig($packagePath . $folderName . '/config.core.php')) { $this->addFieldError('folderName', $this->modx->lexicon('gitpackagemanagement.package_err_cc_nw', array('package' => $packagePath . $folderName))); $this->modx->log(modX::LOG_LEVEL_ERROR, $this->modx->lexicon('gitpackagemanagement.package_err_cc_nw', array('package' => $packagePath . $folderName))); } if (!$this->checkConfig($packagePath . $folderName . '/_build/build.config.php')) { $this->addFieldError('folderName', $this->modx->lexicon('gitpackagemanagement.package_err_bc_nw', array('package' => $packagePath . $folderName))); $this->modx->log(modX::LOG_LEVEL_ERROR, $this->modx->lexicon('gitpackagemanagement.package_err_bc_nw', array('package' => $packagePath . $folderName))); } /** * If no error was added in block above, cloning and installation part begins */ if (!$this->hasErrors()) { /** * Parse config file to objects */ if ($this->setConfig($packagePath . $folderName) == false) { return false; } /** @var string packageCorePath Path to core of cloned repository*/ $this->packageCorePath = $packagePath . $folderName . "/core/components/" . $this->config->getLowCaseName() . "/"; $this->packageCorePath = str_replace('\\', '/', $this->packageCorePath); /** @var string packageAssetsPath Path to assets of cloned repository */ $this->packageAssetsPath = $packagePath . $folderName . "/assets/components/" . $this->config->getLowCaseName() . "/"; $this->packageAssetsPath = str_replace('\\', '/', $this->packageAssetsPath); /** @var string $packagesUrl Base url for packages directory */ $packagesUrl = $this->modx->getOption('gitpackagemanagement.packages_base_url', null, null); /** @var string packageAssetsUrl URL of assets of cloned repository */ $this->packageAssetsUrl = $packagesUrl . $folderName . '/assets/components/' . $this->config->getLowCaseName() . '/'; $this->modx->log(modX::LOG_LEVEL_INFO, '<br /><strong>INSTALLATION START</strong>'); /** * Start installation process */ $this->installPackage($packagePath . $folderName); /** * Create database record for cloned repository */ $this->object->set('version', $this->config->getVersion()); $this->object->set('description', $this->config->getDescription()); $this->object->set('author', $this->config->getAuthor()); $this->object->set('name', $this->config->getName()); $this->object->set('dir_name', $folderName); } $this->modx->log(modX::LOG_LEVEL_INFO, 'COMPLETED'); return parent::beforeSave(); }