Example #1
0
 /**
  * Loads the properties of package.yml.
  */
 private function loadProperties()
 {
     static $cache = null;
     if (is_null($cache)) {
         $cache = rex_file::getCache(rex_path::cache('packages.cache'));
     }
     $id = $this->getPackageId();
     $file = $this->getPath(self::FILE_PACKAGE);
     if (!file_exists($file)) {
         $this->propertiesLoaded = true;
         return;
     }
     if (isset($cache[$id]) && (!rex::isBackend() || !($user = rex::getUser()) || !$user->isAdmin() || $cache[$id]['timestamp'] >= filemtime($file))) {
         $properties = $cache[$id]['data'];
     } else {
         $properties = rex_file::getConfig($file);
         $cache[$id]['timestamp'] = filemtime($file);
         $cache[$id]['data'] = $properties;
         static $registeredShutdown = false;
         if (!$registeredShutdown) {
             $registeredShutdown = true;
             register_shutdown_function(function () use(&$cache) {
                 foreach ($cache as $package => $_) {
                     if (!rex_package::exists($package)) {
                         unset($cache[$package]);
                     }
                 }
                 rex_file::putCache(rex_path::cache('packages.cache'), $cache);
             });
         }
     }
     foreach ($properties as $key => $value) {
         if (!isset($this->properties[$key])) {
             $this->properties[$key] = rex_i18n::translateArray($value, false, [$this, 'i18n']);
         }
     }
     $this->propertiesLoaded = true;
 }
Example #2
0
 /**
  * Loads the properties of package.yml.
  */
 public function loadProperties()
 {
     static $cache = null;
     if (is_null($cache)) {
         $cache = rex_file::getCache(rex_path::coreCache('packages.cache'));
     }
     $id = $this->getPackageId();
     $file = $this->getPath(self::FILE_PACKAGE);
     if (!file_exists($file)) {
         $this->propertiesLoaded = true;
         return;
     }
     if (isset($cache[$id]) && (!rex::isBackend() || !($user = rex::getUser()) || !$user->isAdmin() || $cache[$id]['timestamp'] >= filemtime($file))) {
         $properties = $cache[$id]['data'];
     } else {
         try {
             $properties = rex_file::getConfig($file);
             $cache[$id]['timestamp'] = filemtime($file);
             $cache[$id]['data'] = $properties;
             static $registeredShutdown = false;
             if (!$registeredShutdown) {
                 $registeredShutdown = true;
                 register_shutdown_function(function () use(&$cache) {
                     foreach ($cache as $package => $_) {
                         if (!rex_package::exists($package)) {
                             unset($cache[$package]);
                         }
                     }
                     rex_file::putCache(rex_path::coreCache('packages.cache'), $cache);
                 });
             }
         } catch (rex_yaml_parse_exception $exception) {
             if ($this->isInstalled()) {
                 throw $exception;
             }
             $properties = [];
         }
     }
     $this->properties = array_intersect_key($this->properties, ['install' => null, 'status' => null]);
     if ($properties) {
         foreach ($properties as $key => $value) {
             if (isset($this->properties[$key])) {
                 continue;
             }
             if ('supportpage' !== $key) {
                 $value = rex_i18n::translateArray($value, false, [$this, 'i18n']);
             } elseif (!preg_match('@^https?://@i', $value)) {
                 $value = 'http://' . $value;
             }
             $this->properties[$key] = $value;
         }
     }
     $this->propertiesLoaded = true;
 }