/** * Calculate hashes for current version * * @return array */ protected function loadHashesForInstalledFiles() { $result = array(); $module = $this->getModuleInstalled(); if ($module) { $pack = new \XLite\Core\Pack\Module($module); foreach ($pack->getDirectoryIterator() as $file) { if ($file->isFile()) { $relativePath = \Includes\Utils\FileManager::getRelativePath($file->getPathname(), LC_DIR_ROOT); if ($relativePath) { $result[$relativePath] = \Includes\Utils\FileManager::getHash($file->getPathname(), true); } } } } return $result ?: $this->getHashes(true); }
/** * 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; }
/** * Uninstall module * * @return void */ protected function doActionUninstall() { $module = $this->getModule(); if ($module) { $pack = new \XLite\Core\Pack\Module($module); $dirs = $pack->getDirs(); $nonWritableDirs = array(); // Check permissions foreach ($dirs as $dir) { if (!\Includes\Utils\FileManager::isDirWriteable($dir)) { $nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT); } } $params = array('name' => $module->getActualName()); if (empty($nonWritableDirs)) { $yaml = \Includes\Utils\FileManager::read(\Includes\Utils\ModulesManager::getModuleYAMLFile($module->getAuthor(), $module->getName())); // Remove from FS foreach ($dirs as $dir) { \Includes\Utils\FileManager::unlinkRecursive($dir); } // Disable this and depended modules \Includes\Utils\ModulesManager::disableModule($module->getActualName()); \Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName()); // Remove from DB \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->delete($module); if ($module->getModuleID()) { $message = 'A DB error occured while uninstalling the module "{{name}}"'; $this->showError(__FUNCTION__, $message, $params); } else { if (!empty($yaml)) { \XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml); } $message = 'The module "{{name}}" has been uninstalled successfully'; $this->showInfo(__FUNCTION__, $message, $params); } // To restore previous state \XLite\Core\Marketplace::getInstance()->saveAddonsList(0); // Flag to rebuild cache \XLite::setCleanUpCacheFlag(true); } else { $message = 'Unable to delete module "{{name}}" files: some dirs have no writable permissions: {{dirs}}'; $this->showError(__FUNCTION__, $message, $params + array('dirs' => implode(', ', $nonWritableDirs))); } } }