Пример #1
0
 protected function checkUpdates()
 {
     try {
         $app_settings_model = new waAppSettingsModel();
         $time = $app_settings_model->get($this->application, 'update_time');
     } catch (waDbException $e) {
         if ($e->getCode() == 2002 && !waSystemConfig::isDebug()) {
             return;
         } else {
             // table doesn't exist
             $time = null;
         }
     } catch (waException $e) {
         return;
     }
     if (!$time) {
         try {
             $this->install();
         } catch (waException $e) {
             waLog::log($e->__toString());
             throw $e;
         }
         $ignore_all = true;
     } else {
         $ignore_all = false;
     }
     if (!self::isDebug()) {
         $cache = new waVarExportCache('updates', 0, $this->application);
         if ($cache->isCached() && $cache->get() <= $time) {
             return;
         }
     }
     $path = $this->getAppPath() . '/lib/updates';
     $cache_database_dir = $this->getPath('cache') . '/db';
     if (file_exists($path)) {
         $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
         $files = array();
         foreach ($iterator as $file) {
             /**
              * @var SplFileInfo $file
              */
             if ($file->isFile() && preg_match('/^[0-9]+\\.php$/', $file->getFilename())) {
                 $t = substr($file->getFilename(), 0, -4);
                 if ($t > $time) {
                     $files[$t] = $file->getPathname();
                 }
             }
         }
         ksort($files);
         if (!self::isDebug()) {
             // get last time
             if ($files) {
                 $keys = array_keys($files);
                 $cache->set(end($keys));
             } else {
                 $cache->set($time ? $time : 1);
             }
         }
         foreach ($files as $t => $file) {
             try {
                 if (!$ignore_all) {
                     include $file;
                     waFiles::delete($cache_database_dir);
                     $app_settings_model->set($this->application, 'update_time', $t);
                 }
             } catch (Exception $e) {
                 if (waSystemConfig::isDebug()) {
                     echo $e;
                 }
                 // log errors
                 waLog::log($e->__toString());
                 break;
             }
         }
     } else {
         $t = 1;
     }
     if ($ignore_all) {
         if (!isset($t) || !$t) {
             $t = 1;
         }
         if (!isset($app_settings_model)) {
             $app_settings_model = new waAppSettingsModel();
         }
         $app_settings_model->set($this->application, 'update_time', $t);
     }
     if (isset($this->info['edition']) && $this->info['edition']) {
         if (!isset($app_settings_model)) {
             $app_settings_model = new waAppSettingsModel();
         }
         if (!$app_settings_model->get($this->application, 'edition')) {
             $file_sql = $this->getAppPath('lib/config/app.' . $this->info['edition'] . '.sql');
             if (file_exists($file_sql)) {
                 self::executeSQL($file_sql, 1);
             }
             $app_settings_model->set($this->application, 'edition', $this->info['edition']);
         }
     }
 }
 public function checkUpdates()
 {
     try {
         $app_settings_model = new waAppSettingsModel();
         $time = $app_settings_model->get($this->application, 'update_time');
     } catch (waDbException $e) {
         // Can't connect to MySQL server
         if ($e->getCode() == 2002) {
             throw $e;
         } elseif (!empty($app_settings_model)) {
             $time = null;
             $row = $app_settings_model->getByField(array('app_id' => $this->application, 'name' => 'update_time'));
             if ($row) {
                 $time = $row['value'];
             }
         } elseif ($this->application != 'webasyst' && $this->environment == 'frontend') {
             wa('webasyst');
         }
     } catch (waException $e) {
         return;
     }
     if (empty($time)) {
         try {
             $this->install();
         } catch (waException $e) {
             waLog::log($e->__toString());
             throw $e;
         }
         $ignore_all = true;
         $time = null;
     } else {
         $ignore_all = false;
     }
     if (!self::isDebug()) {
         $cache = new waVarExportCache('updates', 0, $this->application);
         if ($cache->isCached() && $cache->get() <= $time) {
             return;
         }
     }
     $path = $this->getAppPath() . '/lib/updates';
     $cache_database_dir = $this->getPath('cache') . '/db';
     if (file_exists($path)) {
         $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
         $files = array();
         foreach ($iterator as $file) {
             /**
              * @var SplFileInfo $file
              */
             if ($file->isFile() && preg_match('/^[0-9]+\\.php$/', $file->getFilename())) {
                 $t = substr($file->getFilename(), 0, -4);
                 if ($t > $time) {
                     $files[$t] = $file->getPathname();
                 }
             }
         }
         ksort($files);
         if (!self::isDebug()) {
             // get last time
             if ($files) {
                 $keys = array_keys($files);
                 $cache->set(end($keys));
             } else {
                 $cache->set($time ? $time : 1);
             }
         }
         foreach ($files as $t => $file) {
             try {
                 if (!$ignore_all) {
                     $this->includeUpdate($file);
                     waFiles::delete($cache_database_dir);
                     $app_settings_model->set($this->application, 'update_time', $t);
                 }
             } catch (Exception $e) {
                 if (waSystemConfig::isDebug()) {
                     echo $e;
                 }
                 // log errors
                 waLog::log($e->__toString());
                 break;
             }
         }
     } else {
         $t = 1;
     }
     if ($ignore_all) {
         if (!isset($t) || !$t) {
             $t = 1;
         }
         if (!isset($app_settings_model)) {
             $app_settings_model = new waAppSettingsModel();
         }
         $app_settings_model->set($this->application, 'update_time', $t);
     }
     if (isset($this->info['edition']) && $this->info['edition']) {
         if (!isset($app_settings_model)) {
             $app_settings_model = new waAppSettingsModel();
         }
         if (!$app_settings_model->get($this->application, 'edition')) {
             $app_settings_model->set($this->application, 'edition', $this->info['edition']);
         }
     }
 }
 protected function checkUpdates()
 {
     $app_settings_model = new waAppSettingsModel();
     $time = $app_settings_model->get(array($this->app_id, $this->id), 'update_time');
     if (!$time) {
         try {
             $this->install();
         } catch (Exception $e) {
             waLog::log($e->getMessage());
             throw $e;
         }
         $ignore_all = true;
     } else {
         $ignore_all = false;
     }
     $is_debug = waSystemConfig::isDebug();
     if (!$is_debug) {
         $cache = new waVarExportCache('updates', 0, $this->app_id . "." . $this->id);
         if ($cache->isCached() && $cache->get() <= $time) {
             return;
         }
     }
     $path = $this->path . '/lib/updates';
     $cache_database_dir = wa()->getConfig()->getPath('cache') . '/db';
     if (file_exists($path)) {
         $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
         $files = array();
         foreach ($iterator as $file) {
             /**
              * @var SplFileInfo $file
              */
             if ($file->isFile() && preg_match('/^[0-9]+\\.php$/', $file->getFilename())) {
                 $t = substr($file->getFilename(), 0, -4);
                 if ($t > $time) {
                     $files[$t] = $file->getPathname();
                 }
             }
         }
         ksort($files);
         if (!$is_debug) {
             // get last time
             if ($files) {
                 $keys = array_keys($files);
                 $cache->set(end($keys));
             } else {
                 $cache->set($time ? $time : 1);
             }
         }
         foreach ($files as $t => $file) {
             try {
                 if (!$ignore_all) {
                     include $file;
                     waFiles::delete($cache_database_dir);
                     $app_settings_model->set(array($this->app_id, $this->id), 'update_time', $t);
                 }
             } catch (Exception $e) {
                 if ($is_debug) {
                     echo $e;
                 }
                 // log errors
                 waLog::log($e->__toString());
                 break;
             }
         }
     } else {
         $t = 1;
     }
     if ($ignore_all) {
         if (!isset($t) || !$t) {
             $t = 1;
         }
         $app_settings_model->set(array($this->app_id, $this->id), 'update_time', $t);
     }
 }