Ejemplo n.º 1
0
 /**
  * Get the new module presenter class of the specified name provided.
  * It contains data from its instance, the disk, the database and from the marketplace if exists.
  *
  * @param string $name The technical name of the module
  *
  * @return \PrestaShop\PrestaShop\Adapter\Module\Module
  */
 public function getModule($name)
 {
     $php_file_path = _PS_MODULE_DIR_ . $name . '/' . $name . '.php';
     /* Data which design the module class */
     $attributes = array('name' => $name);
     $disk = array();
     $database = array();
     // Get filemtime of module main class (We do this directly with an error suppressor to go faster)
     $current_filemtime = (int) @filemtime($php_file_path);
     // We check that we have data from the marketplace
     try {
         $module_catalog_data = $this->adminModuleProvider->getCatalogModules(array('name' => $name));
         $attributes = array_merge($attributes, (array) array_shift($module_catalog_data));
     } catch (Exception $e) {
         $this->logger->alert($this->translator->trans('Loading data from Addons failed. %error_details%', array('%error_details%' => $e->getMessage()), 'Admin.Modules.Notification'));
     }
     // Now, we check that cache is up to date
     if (isset($this->cache[$name]['disk']['filemtime']) && $this->cache[$name]['disk']['filemtime'] === $current_filemtime) {
         // OK, cache can be loaded and used directly
         $attributes = array_merge($attributes, $this->cache[$name]['attributes']);
         $disk = $this->cache[$name]['disk'];
     } else {
         // NOPE, we have to fulfil the cache with the module data
         $disk = array('filemtime' => $current_filemtime, 'filemtime' => $current_filemtime, 'is_present' => (int) $this->moduleProvider->isOnDisk($name), 'is_valid' => 0, 'version' => null);
         $main_class_attributes = array();
         if ($this->moduleProvider->isModuleMainClassValid($name)) {
             require_once $php_file_path;
             // We load the main class of the module, and get its properties
             $tmp_module = \PrestaShop\PrestaShop\Adapter\ServiceLocator::get($name);
             foreach (array('warning', 'name', 'tab', 'displayName', 'description', 'author', 'author_uri', 'limited_countries', 'need_instance') as $data_to_get) {
                 if (isset($tmp_module->{$data_to_get})) {
                     $main_class_attributes[$data_to_get] = $tmp_module->{$data_to_get};
                 }
             }
             $main_class_attributes['parent_class'] = get_parent_class($name);
             $main_class_attributes['is_configurable'] = (int) method_exists($tmp_module, 'getContent');
             $disk['is_valid'] = 1;
             $disk['version'] = $tmp_module->version;
             $attributes = array_merge($attributes, $main_class_attributes);
         } else {
             $main_class_attributes['warning'] = 'Invalid module class';
         }
         $this->cache[$name]['attributes'] = $main_class_attributes;
         $this->cache[$name]['disk'] = $disk;
     }
     foreach (array('logo.png', 'logo.gif') as $logo) {
         $logo_path = _PS_MODULE_DIR_ . $name . DIRECTORY_SEPARATOR . $logo;
         if (file_exists($logo_path)) {
             $attributes['img'] = __PS_BASE_URI__ . basename(_PS_MODULE_DIR_) . '/' . $name . '/' . $logo;
             break;
         }
     }
     // Get data from database
     $database = $this->moduleProvider->findByName($name);
     return new Module($attributes, $disk, $database);
 }
Ejemplo n.º 2
0
 /**
  * Shortcut to the module data provider in order to know if a module is installed
  *
  * @param string $name The technical module name
  * @return bool True is installed
  */
 public function isInstalled($name)
 {
     return $this->moduleProvider->isInstalled($name);
 }