public function execute()
 {
     if ($this->thread_id = waRequest::get('thread_id', false)) {
         $cache = new waSerializeCache($this->getApp() . '.' . $this->thread_id);
         $this->urls = $cache->get();
         $cache->delete();
     }
     if ($this->urls) {
         wa()->getStorage()->close();
         ob_start();
         try {
             $this->model = new waAppSettingsModel();
             $log_level = waSystemConfig::isDebug() ? waInstaller::LOG_DEBUG : waInstaller::LOG_WARNING;
             $updater = new waInstaller($log_level, $this->thread_id);
             $this->getStorage()->close();
             $updater->init();
             $this->model->ping();
             $storage = wa()->getStorage();
             $storage->close();
             $this->urls = $updater->update($this->urls);
             if (waRequest::request('install')) {
                 $this->install();
             }
             $this->response['sources'] = $this->getResult();
             $this->response['current_state'] = $updater->getState();
             $this->response['state'] = $updater->getFullState(waRequest::get('mode', 'apps'));
             //cleanup cache
             $this->cleanup();
             //update themes
             foreach ($this->urls as $url) {
                 if (preg_match('@(wa-apps/)?(.+)/themes/(.+)@', $url['slug'], $matches)) {
                     try {
                         $theme = new waTheme($matches[3], $matches[2]);
                         $theme->update();
                     } catch (Exception $ex) {
                         waLog::log(sprintf('Error during theme %s@%s update: %s', $matches[3], $matches[2], $ex->getMessage()));
                     }
                 }
             }
             //and again cleanup
             $this->cleanup();
             $this->getConfig()->setCount(false);
             $response = $this->getResponse();
             $response->addHeader('Content-Type', 'application/json; charset=utf-8');
             $response->sendHeaders();
         } catch (Exception $ex) {
             $this->setError($ex->getMessage());
         }
         if ($ob = ob_get_clean()) {
             $this->response['warning'] = $ob;
             waLog::log('Output at ' . __METHOD__ . ': ' . $ob);
         }
     } else {
         throw new Exception('nothing to update');
     }
 }
Example #2
0
 public static function saveDomainsSettings($domains_settings)
 {
     $app_settings_model = new waAppSettingsModel();
     $routing = wa()->getRouting();
     $domains_routes = $routing->getByApp('shop');
     $app_settings_model->set(shopPricePlugin::$plugin_id, 'domains_settings', json_encode($domains_settings));
     $cache = new waSerializeCache('shopPricePlugin');
     if ($cache && $cache->isCached()) {
         $cache->delete();
     }
 }
 private static function setCacheValue($key, $value, $path = null)
 {
     $key .= '.' . self::$locale;
     if ($path) {
         $key .= '.' . md5($path);
     }
     $key = md5($key);
     if (class_exists('waSerializeCache')) {
         $cacher = new waSerializeCache($key, self::$cache_ttl, 'installer');
         $cacher->set($value);
     }
     return $value;
 }
Example #4
0
 public static function saveDomainsSettings($domains_settings)
 {
     $app_settings_model = new waAppSettingsModel();
     $routing = wa()->getRouting();
     $domains_routes = $routing->getByApp('shop');
     foreach ($domains_routes as $domain => $routes) {
         foreach ($routes as $route) {
             $domain_route = md5($domain . '/' . $route['url']);
             foreach (shopOnestepPlugin::$default_settings['templates'] as $id => $template) {
                 $tpl_full_path = $template['tpl_path'] . $domain_route . '_' . $template['tpl_name'] . '.' . $template['tpl_ext'];
                 $template_path = wa()->getDataPath($tpl_full_path, $template['public'], 'shop', true);
                 @unlink($template_path);
                 if (empty($domains_settings[$domain_route]['templates'][$id]['reset_tpl'])) {
                     $source_path = wa()->getAppPath($template['tpl_path'] . $template['tpl_name'] . '.' . $template['tpl_ext'], 'shop');
                     $source_content = file_get_contents($source_path);
                     if (!isset($domains_settings[$domain_route]['templates'][$id]['template'])) {
                         continue;
                     }
                     $post_template = $domains_settings[$domain_route]['templates'][$id]['template'];
                     if (preg_replace('/\\s/', '', $source_content) != preg_replace('/\\s/', '', $post_template)) {
                         $f = fopen($template_path, 'w');
                         if (!$f) {
                             throw new waException('Не удаётся сохранить шаблон. Проверьте права на запись ' . $template_path);
                         }
                         fwrite($f, $post_template);
                         fclose($f);
                     }
                 }
             }
             unset($domains_settings[$domain_route]['templates']);
         }
     }
     $app_settings_model->set(shopOnestepPlugin::$plugin_id, 'domains_settings', json_encode($domains_settings));
     $cache = new waSerializeCache('shopOnestepPlugin');
     if ($cache && $cache->isCached()) {
         $cache->delete();
     }
 }
Example #5
0
<?php

$sqls = array();
$sqls[] = <<<SQL
UPDATE `wa_app_settings`
SET app_id = CONCAT('blog.', SUBSTR(name, 8, POSITION('.' IN SUBSTR(name, 8)) - 1)),
name = SUBSTR(name, 8 + POSITION('.' IN SUBSTR(name, 8)))
WHERE `app_id`= 'blog' AND `name` LIKE 'plugin.%'
SQL;
$model = new waModel();
foreach ($sqls as $sql) {
    try {
        $model->exec($sql);
    } catch (Exception $ex) {
        if (class_exists('waLog')) {
            waLog::log(basename(__FILE__) . ': ' . $ex->getMessage(), 'blog-update.log');
        }
    }
}
$cache = new waSerializeCache('app_settings/blog', SystemConfig::isDebug() ? 600 : 86400, 'webasyst');
$cache->delete();
 public function allowedAddress()
 {
     $cache = new waSerializeCache(__CLASS__ . __FUNCTION__, 86400, 'webasyst');
     if (!($addresses = $cache->get())) {
         $addresses = array();
         /* countries */
         $countries = $this->request('ems.get.locations', array('type' => 'countries'));
         $country_model = new waCountryModel();
         $map = $country_model->getAll('iso2letter');
         $address = array('country' => array());
         foreach ($countries['locations'] as $country) {
             if (ifset($country['type']) == 'countries' && ($value = strtolower(ifset($country['value']))) && isset($map[$value])) {
                 $address['country'][] = $map[$value]['iso3letter'];
             }
         }
         $addresses[] = $address;
         /* regions */
         $region_model = new waRegionModel();
         $address = array('country' => 'rus', 'region' => array());
         $map = $region_model->getByCountry('rus');
         foreach ($map as $region) {
             if ($this->findTo(array('country' => 'rus', 'region_name' => $region['name']))) {
                 $address['region'][] = $region['code'];
             }
         }
         $addresses[] = $address;
         $cache->set($addresses);
     }
     return $addresses;
 }
 public function execute()
 {
     $this->init();
     try {
         $updater = new waInstaller(waInstaller::LOG_TRACE);
         $state = $updater->getState();
         if (!isset($state['stage_status']) || $state['stage_name'] != waInstaller::STAGE_NONE && $state['heartbeat'] > waInstaller::TIMEOUT_RESUME + 5 || $state['stage_name'] == waInstaller::STAGE_UPDATE && $state['heartbeat'] || $state['stage_status'] == waInstaller::STATE_ERROR && $state['heartbeat'] || $state['stage_name'] == waInstaller::STAGE_NONE && $state['heartbeat'] === false) {
             $updater->setState();
             $state = $updater->getState();
             $apps = installerHelper::getInstaller();
             $items = $apps->getUpdates(null, $this->getItemsList());
             $queue_apps = array();
             $execute_actions = array(waInstallerApps::ACTION_INSTALL, waInstallerApps::ACTION_CRITICAL_UPDATE, waInstallerApps::ACTION_UPDATE);
             foreach ($items as $app_id => $info) {
                 if (!empty($info['download_url']) && in_array($info['action'], $execute_actions)) {
                     $info['subject'] = 'app';
                     if ($app_id == 'installer') {
                         foreach ($info['download_url'] as $target => $url) {
                             $_info = $info;
                             $_info['download_url'] = $url;
                             $_info['name'] = _w('Webasyst Framework') . ' (' . $target . ')';
                             $this->add($target, $_info);
                             $queue_apps[$target] = $_info;
                             unset($_info);
                         }
                     } else {
                         $target = 'wa-apps/' . $app_id;
                         $this->add($target, $info, $app_id);
                         $queue_apps[$target] = $info;
                     }
                 }
                 foreach (array('themes', 'plugins') as $type) {
                     if (!empty($info[$type]) && is_array($info[$type])) {
                         foreach ($info[$type] as $extra_id => $extras_info) {
                             if (!empty($extras_info['download_url']) && in_array($extras_info['action'], $execute_actions)) {
                                 $extras_info['subject'] = 'app_' . $type;
                                 if ($type == 'themes' && is_array($extras_info['download_url'])) {
                                     foreach ($extras_info['download_url'] as $target => $url) {
                                         $__info = $extras_info;
                                         $__info['download_url'] = $url;
                                         $__info['slug'] = preg_replace('@^wa-apps/@', '', $target);
                                         $__info['app'] = preg_replace('@^wa-apps/([^/]+)/.+$@', '$1', $target);
                                         if (!isset($queue_apps[$target])) {
                                             if ($__info['app'] == $app_id || empty($items[$__info['app']][$type][$extra_id])) {
                                                 if (!empty($items[$__info['app']][$type][$extra_id]['name'])) {
                                                     $__info['name'] .= " ({$info['name']})";
                                                 } elseif ($app_info = wa()->getAppInfo($__info['app'])) {
                                                     $__info['name'] .= " ({$app_info['name']})";
                                                 } else {
                                                     $__info['name'] .= " ({$__info['app']})";
                                                 }
                                                 $this->add($target, $__info);
                                                 $queue_apps[$target] = $__info;
                                             }
                                         }
                                     }
                                 } else {
                                     if (!empty($info['name'])) {
                                         $extras_info['name'] .= " ({$info['name']})";
                                     }
                                     if (strpos($app_id, '/')) {
                                         //system plugins
                                         $target = $app_id . '/' . $extra_id;
                                     } else {
                                         $target = 'wa-apps/' . $app_id . '/' . $type . '/' . $extra_id;
                                     }
                                     $this->add($target, $extras_info, $target);
                                     $queue_apps[$target] = $extras_info;
                                 }
                             }
                         }
                     }
                 }
                 unset($info);
             }
             if (!$queue_apps) {
                 throw new waException(_w('Please select items for update'));
             }
             if (!waRequest::get('_')) {
                 $this->setLayout(new installerBackendLayout());
                 $this->getLayout()->assign('no_ajax', true);
             }
             $this->view->assign('action', 'update');
             $this->view->assign('queue_apps', $queue_apps);
             $install = waRequest::request('install');
             $this->view->assign('install', !empty($install) ? 'install' : '');
             $this->view->assign('title', _w('Updates'));
             $this->view->assign('thread_id', $state['thread_id']);
             $this->view->assign('return_url', waRequest::post('return_url'));
             $cache = new waSerializeCache($this->getApp() . '.' . $state['thread_id']);
             $cache->set($this->urls);
         } else {
             $msg = _w('Update is already in progress. Please wait while previous update session is finished before starting update session again.');
             $this->redirect(array('module' => $this->module, 'msg' => installerMessage::getInstance()->raiseMessage($msg, installerMessage::R_FAIL)));
         }
     } catch (Exception $ex) {
         $this->redirect(array('module' => $this->module, 'msg' => installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL)));
     }
 }
 private static function getCacheValue($path, $default = null)
 {
     $key = __CLASS__ . '.' . md5($path);
     $value = $default;
     if (self::$cache_ttl && class_exists('waSerializeCache')) {
         $cache = new waSerializeCache($key, self::$cache_ttl, 'installer');
         if ($cache->isCached()) {
             $value = $cache->get();
         }
     }
     return $value;
 }
 public function execute()
 {
     if ($this->getRequest()->param('blog_id') === false) {
         throw new waException(_w('Blog not found'), 404);
     }
     $this->view->getHelper()->globals($this->getRequest()->param());
     $posts_per_page = max(1, intval($this->getConfig()->getOption('posts_per_page')));
     $post_model = new blogPostModel();
     $options = array();
     if (!$this->appSettings('show_comments', true)) {
         $options['comments'] = false;
     }
     $options['params'] = true;
     $options['text'] = 'cut';
     $options['escape'] = true;
     $is_search = false;
     if (isset($this->search_params["search"])) {
         $plugin = $this->search_params["search"];
         if (!isset($this->search_params["plugin"])) {
             $this->search_params["plugin"] = array();
         }
         if (isset($this->search_params[$plugin])) {
             $this->search_params["plugin"][$plugin] = $this->search_params[$plugin];
             $is_search = true;
         }
     }
     $query = $this->getRequest()->get('query', '', waRequest::TYPE_STRING_TRIM);
     if ($query) {
         $this->search_params['text'] = urldecode($query);
         $options['highlighted'] = true;
     }
     $blogs = blogHelper::getAvailable();
     $posts = $post_model->search($this->search_params, $options, array('blog' => $blogs))->fetchSearchPage($this->page, $posts_per_page);
     $stream_title = false;
     if (isset($this->search_params['contact_id'])) {
         if (count($posts)) {
             reset($posts);
             $post = current($posts);
             $name = $post['user']['name'];
             $is_search = true;
         } else {
             if ($contact = blogHelper::getContactInfo($this->search_params['contact_id'])) {
                 $name = htmlentities($contact['name'], ENT_QUOTES, 'utf-8');
                 $is_search = true;
             } else {
                 throw new waException(_w('Blog not found'), 404);
             }
         }
         $stream_title = sprintf(_w('Posts by %s'), $name);
         $this->getResponse()->setTitle($stream_title);
     } elseif ($is_search) {
         $stream_title = $this->getResponse()->getTitle();
     } elseif (isset($this->search_params['year'])) {
         $stream_title = '';
         if (isset($this->search_params['day'])) {
             $stream_title .= intval($this->search_params['day']) . ' ';
         }
         if (isset($this->search_params['month'])) {
             $stream_title .= _ws(date("F", gmmktime(0, 0, 0, intval($this->search_params['month']), 1))) . ' ';
         }
         $stream_title .= $this->search_params['year'] . ' — ' . $this->getResponse()->getTitle();
         $this->getResponse()->setTitle($stream_title);
     } else {
         if (!empty($this->search_params['text'])) {
             $stream_title = urldecode($this->search_params['text']);
             $this->getResponse()->setTitle($stream_title);
             $is_search = true;
         }
     }
     $this->view->assign('stream_title', $stream_title);
     $pages = $post_model->pageCount();
     $url = wa()->getRouteUrl('blog/frontend', $this->search_params, true);
     if ($pages && $pages < $this->page) {
         $page = min($pages, $this->page);
         $redirect = $url . ($page > 1 ? "?page={$page}" : '');
         $this->getResponse()->redirect($redirect, 302);
     }
     if ($layout = $this->getLayout()) {
         $links = array();
         if ($pages > $this->page) {
             $page = $this->page + 1;
             $links['next'] = "{$url}?page={$page}";
         }
         if ($this->page > 1) {
             $page = $this->page - 1;
             $links['prev'] = $url . ($page > 1 ? "?page={$page}" : '');
         }
         $layout->assign('links', $links);
         if (!$is_search) {
             /*
              * @deprecated fix assigning sidebar_timeline for next version of blog
              * */
             $layout->assign('sidebar_timeline', $post_model->getTimeline($this->search_params['blog_id'], $blogs, $this->search_params));
         }
         if (isset($this->search_params['contact_id'])) {
             $layout->assign('action_info', array('search' => array('contact_id' => $this->search_params['contact_id'])));
         }
         $layout->assign('is_search', $is_search);
     }
     $this->view->assign('is_search', $is_search);
     $this->view->assign('page', $this->page);
     $this->view->assign('is_lazyloading', $this->is_lazyloading);
     $this->view->assign('pages', $pages);
     $this->view->assign('post_count', $post_model->searchCount());
     $this->view->assign('show_comments', !isset($options['comments']) || $options['comments']);
     $this->view->assign('posts_per_page', $posts_per_page);
     $this->view->assign('blog_query', $query);
     /**
      * Backward compatibility with older themes
      * @deprecated
      */
     $this->view->assign('is_concrete_blog', waRequest::param('blog_url') ? true : false);
     $this->view->assign('layout_type', $this->is_lazyloading ? 'lazyloading' : ($this->page > 1 ? 'page' : 'default'));
     if ($this->getConfig()->getOption('can_use_smarty')) {
         foreach ($posts as &$post) {
             try {
                 $post['text'] = $this->view->fetch("string:{$post['text']}", $this->cache_id);
             } catch (SmartyException $ex) {
                 $post['text'] = blogPost::handleTemplateException($ex, $post);
             }
         }
         unset($post);
     }
     $this->view->assign('posts', $posts);
     if ($this->cache_time && false) {
         $this->cache->set(array_keys($posts));
     }
 }
 public function isCached()
 {
     return $this->cache->isCached();
 }