예제 #1
0
 /**
  * {@inheritDoc}
  */
 public function checkModuleMainClass()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'checkModuleMainClass', array());
     return parent::checkModuleMainClass();
 }
예제 #2
0
 /**
  * Uninstall module
  *
  * @param \XLite\Model\Module $module    Module object
  * @param array               &$messages Messages list
  *
  * @return boolean
  */
 public function uninstallModule(\XLite\Model\Module $module, &$messages)
 {
     $result = false;
     // Get module pack
     $pack = new \XLite\Core\Pack\Module($module);
     $dirs = $pack->getDirs();
     $nonWritableDirs = array();
     // Check module directories permissions
     foreach ($dirs as $dir) {
         if (\Includes\Utils\FileManager::isExists($dir) && !\Includes\Utils\FileManager::isDirWriteable($dir)) {
             $nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT);
         }
     }
     $params = array('name' => sprintf('%s v%s (%s)', $module->getModuleName(), $module->getVersion(), $module->getAuthorName()));
     if (empty($nonWritableDirs)) {
         $yamlData = array();
         $yamlFiles = \Includes\Utils\ModulesManager::getModuleYAMLFiles($module->getAuthor(), $module->getName());
         foreach ($yamlFiles as $yamlFile) {
             $yamlData[] = \Includes\Utils\FileManager::read($yamlFile);
         }
         if (!$module->checkModuleMainClass()) {
             $classFile = LC_DIR_CLASSES . \Includes\Utils\Converter::getClassFile($module->getMainClass());
             if (\Includes\Utils\FileManager::isFileReadable($classFile)) {
                 require_once $classFile;
             }
         }
         // Call uninstall event method
         $r = $module->callModuleMethod('callUninstallEvent', 111);
         if (111 == $r) {
             \XLite\Logger::getInstance()->log($module->getActualName() . ': Method callUninstallEvent() was not called');
         }
         // Remove from FS
         foreach ($dirs as $dir) {
             \Includes\Utils\FileManager::unlinkRecursive($dir);
         }
         \Includes\Utils\ModulesManager::disableModule($module->getActualName());
         \Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName());
         // Remove module from DB
         try {
             // Refresh module entity as it was changed by disableModule() method above
             $module = $this->find($module->getModuleID());
             $this->delete($module);
         } catch (\Exception $e) {
             $messages[] = $e->getMessage();
         }
         if ($module->getModuleID()) {
             $messages[] = \XLite\Core\Translation::getInstance()->translate('A DB error occured while uninstalling the module X', $params);
         } else {
             if (!empty($yamlData)) {
                 foreach ($yamlData as $yaml) {
                     \XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml);
                 }
             }
             $messages[] = \XLite\Core\Translation::getInstance()->translate('The module X has been uninstalled successfully', $params);
             $result = true;
         }
     } else {
         $messages[] = \XLite\Core\Translation::getInstance()->translate('Unable to delete module X files: some dirs have no writable permissions: Y', $params + array('dirs' => implode(', ', $nonWritableDirs)));
     }
     return $result;
 }