public function execute() { $cache = null; if ($cache_time = $this->getConfig()->getOption('cache_time')) { //$cache = new waSerializeCache('pages/'.$domain.$url.'page'); } $page = array(); if ($cache && $cache->isCached()) { $page = $cache->get(); } else { $site = new siteFrontend(); if (waRequest::param('error')) { $page = array(); } else { $page = $site->getPage(waRequest::param('url', '')); } if ($page && $cache) { $cache->set($page); } } if (!waRequest::isXMLHttpRequest()) { $this->setLayout(new siteFrontendLayout()); } try { $this->executeAction(new siteFrontendAction($page)); } catch (Exception $e) { if (waSystemConfig::isDebug()) { echo $e; } else { waSystem::setActive('site'); $this->executeAction(new siteFrontendAction($e)); } } }
protected function writeToFile($file, $v) { if (!file_exists($file) && is_writable(dirname($file)) || is_writable($file)) { return file_put_contents($file, "<?php\nreturn " . var_export($v, true) . ";"); } elseif (waSystemConfig::isDebug()) { throw new waException("Cannot write to cache file " . $file, 601); } }
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'); } }
public function decorate($response) { if (is_array($response)) { $response = $this->parseArray($response); } if (waSystemConfig::isDebug() && version_compare(PHP_VERSION, '5.4.0') >= 0) { return json_encode($response, JSON_PRETTY_PRINT); } else { return json_encode($response); } }
protected function writeToFile($file, $v) { $data = serialize(array('time' => time(), 'ttl' => $this->ttl, 'value' => $v)); if (!file_exists($file) || is_writable($file)) { $r = @file_put_contents($file, $data); if ($r) { @chmod($file, 0664); } return $r; } elseif (waSystemConfig::isDebug()) { throw new waException("Cannot write to cache file " . $file, 601); } }
public function display($clear_assign = true) { if (waSystemConfig::isDebug()) { return parent::display($clear_assign); } try { return parent::display($clear_assign); } catch (SmartyCompilerException $e) { $message = preg_replace('/(on\\sline\\s[0-9]+).*$/i', '$1', $e->getMessage()); $message = str_replace($this->getConfig()->getRootPath(), '', $message); throw new SmartyCompilerException($message, $e->getCode()); } }
public function execute() { $message = ''; if (!wa()->getUser()->getRights('webasyst', 'backend')) { $message = _w('Coding sandbox is available for Webasyst admin users only.'); } if (!waSystemConfig::isDebug()) { $message = _w('Coding sandbox works only if Debug mode is enabled in the Installer app.'); } // !!! only allow access from localhost? if ($message) { $this->setTemplate('string:<div class="tripple-padded block"><h2 style="color:red">{$message|escape}</h2></div>'); $this->view->assign('message', $message); } }
public function execute() { // Access control $message = ''; if (!wa()->getUser()->getRights('webasyst', 'backend')) { $message = _w('This application is available for Webasyst admin users only.'); } if (!waSystemConfig::isDebug()) { $message = _w('This application works only when Debug mode is enabled in the Installer app.'); } if ($message) { throw new waRightsException($message); } // !!! TODO: only allow access from localhost? eval(waRequest::post('code')); // Welcome to the dark side! }
public function execute() { $comment_id = (int) waRequest::post('spam'); $comment_model = new blogCommentModel(); $comment = $comment_model->getById($comment_id); $this->response['status'] = null; if ($comment) { $comment_model->updateById($comment_id, array('akismet_spam' => 1, 'status' => blogCommentModel::STATUS_DELETED)); $this->response['status'] = blogCommentModel::STATUS_DELETED; $blog_plugin = wa()->getPlugin('akismet'); $akismet = new Akismet(wa()->getRouting()->getUrl('blog', array(), true), $blog_plugin->getSettingValue('api_key')); $akismet->setCommentAuthor($comment['name']); $akismet->setCommentAuthorEmail($comment['email']); $akismet->setCommentContent($comment['text']); if (!waSystemConfig::isDebug() && $blog_plugin->getSettingValue('send_spam')) { $akismet->submitSpam(); } } }
public function add($action, $params = null, $subject_contact_id = null, $contact_id = null) { /** * @var waSystem */ $system = waSystem::getInstance(); /** * @var waAppConfig */ $config = $system->getConfig(); if ($config instanceof waAppConfig) { // Get actions of current application available to log $actions = $config->getLogActions(); // Check action if (!isset($actions[$action])) { if (waSystemConfig::isDebug()) { throw new waException('Unknown action for log ' . $action); } else { return false; } } if ($actions[$action] === false) { return false; } $app_id = $system->getApp(); } else { $app_id = 'wa-system'; } // Save to database $data = array('app_id' => $app_id, 'contact_id' => $contact_id === null ? $system->getUser()->getId() : $contact_id, 'datetime' => date("Y-m-d H:i:s"), 'action' => $action, 'subject_contact_id' => $subject_contact_id); if ($params !== null) { if (is_array($params)) { $params = json_encode($params); } $data['params'] = $params; } return $this->insert($data); }
public function addCss($url, $app_id = false) { if ($app_id) { $url = wa()->getAppStaticUrl($app_id) . $url; $app_info = wa()->getAppInfo($app_id === true ? null : $app_id); $url .= '?' . (isset($app_info['version']) ? $app_info['version'] : '0.0.1'); if (waSystemConfig::isDebug()) { $url .= '.' . time(); } } else { $url = wa()->getRootUrl() . $url; } $this->css[] = $url; return $this; }
public function getApps($system = false) { if (self::$apps === null) { $locale = $this->getUser()->getLocale(); $file = $this->config->getPath('cache', 'config/apps' . $locale); if (!file_exists($this->getConfig()->getPath('config', 'apps'))) { self::$apps = array(); throw new waException('File wa-config/apps.php not found.', 600); } if (!file_exists($file) || filemtime($file) < filemtime($this->getConfig()->getPath('config', 'apps')) || waSystemConfig::isDebug()) { waFiles::create($this->getConfig()->getPath('cache') . '/config'); $all_apps = (include $this->getConfig()->getPath('config', 'apps')); $all_apps['webasyst'] = true; self::$apps = array(); foreach ($all_apps as $app => $enabled) { if ($enabled) { waLocale::loadByDomain($app, $locale); $app_config = $this->getAppPath('lib/config/app.php', $app); if (!file_exists($app_config)) { if (false && SystemConfig::isDebug()) { throw new waException("Config not found. Create config by path " . $app_config); } continue; } $app_info = (include $app_config); $build_file = $app_config = $this->getAppPath('lib/config/build.php', $app); if (file_exists($build_file)) { $app_info['build'] = (include $build_file); } else { if (SystemConfig::isDebug()) { $app_info['build'] = time(); } else { $app_info['build'] = 0; } } $app_info['id'] = $app; $app_info['name'] = _wd($app, $app_info['name']); if (isset($app_info['icon'])) { if (is_array($app_info['icon'])) { foreach ($app_info['icon'] as $size => $url) { $app_info['icon'][$size] = 'wa-apps/' . $app . '/' . $url; } } else { $app_info['icon'] = array(48 => 'wa-apps/' . $app . '/' . $app_info['icon']); } } else { $app_info['icon'] = array(); } if (isset($app_info['img'])) { $app_info['img'] = 'wa-apps/' . $app . '/' . $app_info['img']; } else { $app_info['img'] = isset($app_info['icon'][48]) ? $app_info['icon'][48] : 'wa-apps/' . $app . '/img/' . $app . ".png"; } if (!isset($app_info['icon'][48])) { $app_info['icon'][48] = $app_info['img']; } if (!isset($app_info['icon'][24])) { $app_info['icon'][24] = $app_info['icon'][48]; } if (!isset($app_info['icon'][16])) { $app_info['icon'][16] = $app_info['icon'][24]; } self::$apps[$app] = $app_info; } } if (!file_exists($file) || filemtime($file) < filemtime($this->getConfig()->getPath('config', 'apps'))) { waUtils::varExportToFile(self::$apps, $file); } } else { self::$apps = (include $file); waLocale::loadByDomain('webasyst'); } } if ($system) { return self::$apps; } else { $apps = self::$apps; unset($apps['webasyst']); return $apps; } }
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']); } } }
private function validate() { libxml_use_internal_errors(true); shopYandexmarketPlugin::path('shops.dtd'); $this->loadDom($this->data['path']['offers']); $valid = @$this->dom->validate(); $strict = waSystemConfig::isDebug(); if ((!$valid || $strict) && ($r = libxml_get_errors())) { $this->data['error'] = array(); $error = array(); if ($valid) { $this->data['error'][] = array('level' => 'info', 'message' => 'YML-файл валиден'); } else { $this->data['error'][] = array('level' => 'error', 'message' => 'YML-файл содержит ошибки'); } foreach ($r as $er) { /** * @var libXMLError $er */ $level_name = ''; switch ($er->level) { case LIBXML_ERR_WARNING: $level_name = 'LIBXML_ERR_WARNING'; break; case LIBXML_ERR_ERROR: $level_name = 'LIBXML_ERR_ERROR'; break; case LIBXML_ERR_FATAL: $level_name = 'LIBXML_ERR_FATAL'; break; } if ($er->code != 505) { $this->data['error'][] = array('level' => $valid ? 'warning' : 'error', 'message' => "{$level_name} #{$er->code} [{$er->line}:{$er->column}]: {$er->message}"); } $error[] = "Error #{$er->code}[{$er->level}] at [{$er->line}:{$er->column}]: {$er->message}"; } if ($valid && count($this->data['error']) == 1) { $this->data['error'] = array(); } $this->error(implode("\n\t", $error)); } }
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 debug() { return waSystemConfig::isDebug(); }
public function execute() { $fm = new shopFollowupModel(); $opm = new shopOrderParamsModel(); $asm = new waAppSettingsModel(); $olm = new shopOrderLogModel(); $cm = new shopCustomerModel(); $om = new shopOrderModel(); $asm->set('shop', 'last_followup_cli', time()); $view = wa()->getView(); $empty_customer = $cm->getEmptyRow(); $general = wa('shop')->getConfig()->getGeneralSettings(); foreach ($fm->getAllEnabled() as $f) { $between_from = date('Y-m-d', strtotime($f['last_cron_time']) - 24 * 3600); $between_to = date('Y-m-d 23:59:59', time() - $f['delay'] - 10 * 3600); $orders = $om->where('paid_date >= ? AND paid_date < ?', $between_from, $between_to)->fetchAll('id'); if ($orders) { $f_param_key = 'followup_' . $f['id']; // Params for all orders with one query $params = $opm->get(array_keys($orders)); // Customer data for all orders with one query $cids = array(); foreach ($orders as $o) { $cids[] = $o['contact_id']; } $customers = $cm->getById($cids); $sent_count = 0; foreach ($orders as $o) { try { // Is there a recipient in the first place? if (empty($o['contact_id'])) { if (waSystemConfig::isDebug()) { waLog::log("Unable to send follow-up #{$f['id']} for order #{$o['id']}: no contact_id"); } continue; } // Check that this is the first order of this customer if ($f['first_order_only']) { $first_order_id = $om->select('MIN(id)')->where('contact_id=? AND paid_date IS NOT NULL', $o['contact_id'])->fetchField(); if ($first_order_id != $o['id']) { if (waSystemConfig::isDebug()) { waLog::log("Skipping follow-up #{$f['id']} for order #{$o['id']}: not the first order of a customer."); } continue; } } $o['params'] = ifset($params[$o['id']], array()); $source = 'backend'; if (!empty($o['params']['storefront'])) { $source = rtrim($o['params']['storefront'], '/') . '/*'; } if ($f['source'] && $f['source'] != $source) { continue; } // Make sure we have not send follow-up for this order yet if (isset($o['params'][$f_param_key])) { if (waSystemConfig::isDebug()) { waLog::log("Skipping follow-up #{$f['id']} for order #{$o['id']}: already sent before."); } continue; } shopHelper::workupOrders($o, true); // Recipient info $customer = ifset($customers[$o['contact_id']], $empty_customer); $contact = new shopCustomer($o['contact_id']); $email = $contact->get('email', 'default'); // this with throw exception if contact does not exist; that's ok if (!$email) { if (waSystemConfig::isDebug()) { waLog::log("Unable to send follow-up #{$f['id']} for order #{$o['id']}: contact has no email"); } continue; } $to = array($email => $contact->getName()); if (self::sendOne($f, $o, $customer, $contact, $to, $view, $general)) { $sent_count++; // Write to order log $olm->add(array('order_id' => $o['id'], 'contact_id' => null, 'action_id' => '', 'text' => sprintf_wp("Follow-up <strong>%s</strong> (%s) sent to customer.", htmlspecialchars($f['name']), $f['id']), 'before_state_id' => $o['state_id'], 'after_state_id' => $o['state_id'])); // Write to order params $opm->insert(array('order_id' => $o['id'], 'name' => $f_param_key, 'value' => date('Y-m-d H:i:s'))); } else { waLog::log("Unable to send follow-up #{$f['id']} for order #{$o['id']}: waMessage->send() returned FALSE."); } } catch (Exception $e) { waLog::log("Unable to send follow-up #{$f['id']} for order #{$o['id']}:\n" . $e); } } /** * Notify plugins about sending followup * @event followup_send * @param array[string]int $params['sent_count'] number of emails successfully sent * @param array[string]int $params['id'] followup_id * @return void */ $event_params = $f; $event_params['sent_count'] = $sent_count; wa()->event('followup_send', $event_params); } $fm->updateById($f['id'], array('last_cron_time' => $between_to)); } }
public function block($id, $params = array()) { if ($id && wa()->appExists('site')) { wa('site'); $model = new siteBlockModel(); $block = $model->getById($id); if (!$block && strpos($id, '.') !== false) { list($app_id, $id) = explode('.', $id); $path = $this->getConfig()->getAppsPath($app_id, 'lib/config/site.php'); if (file_exists($path)) { $site_config = (include $path); if (isset($site_config['blocks'][$id])) { if (!is_array($site_config['blocks'][$id])) { $block = array('content' => $site_config['blocks'][$id]); } else { $block = $site_config['blocks'][$id]; } } } } if ($block) { try { $this->view->assign($params); return $this->view->fetch('string:' . $block['content']); } catch (Exception $e) { if (waSystemConfig::isDebug()) { return '<pre class="error">' . htmlentities($e->getMessage(), ENT_QUOTES, 'utf-8') . "</pre>"; } else { waLog::log($e->__toString()); return '<div class="error">' . _ws('Syntax error at block') . ' ' . $id . '</div>'; } } } } return ''; }
protected function create($type, $id, $path, $params = array()) { $template_id = 'wapattern'; $template_path = wa()->getConfig()->getPath('plugins') . '/' . $type . '/' . $template_id . '/'; if (!file_exists($path)) { try { $path .= '/'; mkdir($path); // lib mkdir($path . 'lib'); waFiles::protect($path . 'lib'); $plugin_class = null; mkdir($path . 'lib/classes'); // config mkdir($path . 'lib/config'); // app description $plugin = array('name' => empty($params['name']) ? ucfirst($id) : $params['name'], 'description' => '', 'icon' => 'img/' . $id . '.png', 'version' => empty($params['version']) ? '1.0.0' : $params['version'], 'vendor' => empty($params['vendor']) ? '' : $params['vendor']); waUtils::varExportToFile($plugin, $path . 'lib/config/plugin.php'); switch ($type) { case 'payment': #settings if (isset($params['settings'])) { waUtils::varExportToFile(array(), $path . 'lib/config/settings.php'); } #plugin class $template_class_path = $template_path . 'lib/' . $template_id . ucfirst($type) . '.class.php'; $class_path = $path . 'lib/' . $id . ucfirst($type) . '.class.php'; $template = file_get_contents($template_class_path); waFiles::write($class_path, str_replace($template_id, $id, $template)); #plugin template mkdir($path . 'templates'); waFiles::protect($path . 'templates'); waFiles::copy($template_path . 'templates/payment.html', $path . 'templates/payment.html'); break; case 'shipping': #settings if (isset($params['settings'])) { waUtils::varExportToFile(array(), $path . 'lib/config/settings.php'); } #plugin class $template_class_path = $template_path . 'lib/' . $template_id . ucfirst($type) . '.class.php'; $class_path = $path . 'lib/' . $id . ucfirst($type) . '.class.php'; $template = file_get_contents($template_class_path); waFiles::write($class_path, str_replace($template_id, $id, $template)); break; default: throw new waException(sprintf("Plugin type \"%s\" not supported yet.\n", $type)); break; } print "Plugin with id \"{$id}\" created!\n"; } catch (waException $ex) { print "Plugin with id \"{$id}\" was NOT created.\n"; if (waSystemConfig::isDebug()) { echo $ex; } else { print "Error:" . $ex->getMessage() . "\n"; } waFiles::delete($path); } } else { print "Plugin with id \"{$id}\" already exists.\n"; } }
/** * Adds a URL to the CSS file list. All added CSS file URLs are available in Smarty templates using {$wa->css()}. * * @param string $url Relative URL of a CSS file. If $app_id is specified, then the URL must be relative to * specified app's directory URL. Otherwise the CSS file URL must be relative to framework's root URL. * @param string|bool $app_id Optional app id * @return waResponse Instance of waResponse class */ public function addCss($url, $app_id = false) { if ($app_id) { $url = wa()->getAppStaticUrl($app_id) . $url; $app_info = wa()->getAppInfo($app_id === true ? null : $app_id); $url .= '?' . (isset($app_info['version']) ? $app_info['version'] : '0.0.1'); if (waSystemConfig::isDebug()) { $url .= '.' . time(); } // Support external links } elseif (strpos($url, '://') === false && strpos($url, '//') !== 0) { $url = wa()->getRootUrl() . $url; } $this->css[] = $url; return $this; }
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); } }
public function __toString() { try { $wa = wa(); $additional_info = ''; } catch (Exception $e) { $wa = null; $additional_info = $e->getMessage(); } $message = nl2br($this->getMessage()); if ($wa && waSystem::getApp()) { $app = $wa->getAppInfo(); $backend_url = $wa->getConfig()->getBackendUrl(true); } else { $app = array(); } if (!waSystemConfig::isDebug() && $wa) { $env = $wa->getEnv(); $file = $code = $this->getCode(); if (!$code || !file_exists(dirname(__FILE__) . '/data/' . $code . '.php')) { $file = 'error'; } include dirname(__FILE__) . '/data/' . $file . '.php'; exit; } if ($wa && $wa->getEnv() == 'cli' || !$wa && php_sapi_name() == 'cli') { return date("Y-m-d H:i:s") . " php " . implode(" ", waRequest::server('argv')) . "\n" . "Error: {$this->getMessage()}\nwith code {$this->getCode()} in '{$this->getFile()}' around line {$this->getLine()}:{$this->getFileContext()}\n" . $this->getTraceAsString() . "\n" . ($additional_info ? "Error while initializing waSystem during error generation: " . $additional_info . "\n" : ''); } elseif ($this->code == 404) { $response = new waResponse(); $response->setStatus(404); $response->sendHeaders(); } $request = htmlentities(var_export($_REQUEST, true), ENT_NOQUOTES, 'utf-8'); $params = htmlentities(var_export(waRequest::param(), true), ENT_NOQUOTES, 'utf-8'); $context = htmlentities($this->getFileContext(), ENT_NOQUOTES, 'utf-8'); $trace = htmlentities($this->getTraceAsString(), ENT_NOQUOTES, 'utf-8'); $result = <<<HTML <div style="width:99%; position:relative; text-align: left;"> \t<h2 id='Title'>{$message}</h2> \t<div id="Context" style="display: block;"> \t\t<h3>Error with code {$this->getCode()} in '{$this->getFile()}' around line {$this->getLine()}:</h3> \t\t<pre>{$context}</pre> \t</div> \t<div id="Trace"> \t\t<h2>Call stack</h2> \t\t<pre>{$trace}</pre> \t</div> \t<div id="Request"> \t\t<h2>Request</h2> \t\t<pre>{$request}</pre> </div> </div> <div style="text-align: left;"> <h2>Params</h2> <pre>{$params}</pre> </div> HTML; if ($additional_info) { $additional_info = htmlentities($additional_info, ENT_NOQUOTES, 'utf-8'); $result .= <<<HTML <div style="text-align: left;"> <h2>Error while initializing waSystem during error generation</h2> <pre>{$additional_info}</pre> </div> HTML; } return $result; }
/** * Trigger event with given $name from current active application. * * @param string $name Event name. * @param mixed $params Parameters passed to event handlers. * @param string[] $array_keys Array of expected template items for UI events. * @return array app_id or plugin_id => data returned from handler (unless null is returned) */ public function event($name, &$params = null, $array_keys = null) { $result = array(); if (is_array($name)) { $event_app_id = $name[0]; $event_system = self::getInstance($event_app_id); $name = $name[1]; } else { $event_app_id = $this->getConfig()->getApplication(); $event_system = $this; } $event_prefix = wa($event_app_id)->getConfig()->getPrefix(); if (!isset(self::$handlers['apps'])) { self::$handlers['apps'] = array(); $cache_file = $this->config->getPath('cache', 'config/handlers'); if (!waSystemConfig::isDebug() && file_exists($cache_file)) { self::$handlers['apps'] = (include $cache_file); } if (!self::$handlers['apps'] || !is_array(self::$handlers['apps'])) { $apps = $this->getApps(); $path = $this->getConfig()->getPath('apps'); foreach ($apps as $app_id => $app_info) { $files = waFiles::listdir($path . '/' . $app_id . '/lib/handlers/'); foreach ($files as $file) { if (substr($file, -12) == '.handler.php') { $file = explode('.', substr($file, 0, -12), 2); self::$handlers['apps'][$file[0]][$file[1]][] = $app_id; } } } if (!waSystemConfig::isDebug()) { waUtils::varExportToFile(self::$handlers['apps'], $cache_file); } } } if (!isset(self::$handlers['plugins'][$event_app_id])) { self::$handlers['plugins'][$event_app_id] = array(); $plugins = $event_system->getConfig()->getPlugins(); foreach ($plugins as $plugin_id => $plugin) { if (!empty($plugin['handlers'])) { foreach ($plugin['handlers'] as $handler_event => $handler_method) { self::$handlers['plugins'][$event_app_id][$handler_event][$plugin_id] = $handler_method; } } } } if (isset(self::$handlers['apps'][$event_app_id][$name])) { $path = $this->getConfig()->getPath('apps'); foreach (self::$handlers['apps'][$event_app_id][$name] as $app_id) { $file_path = $path . '/' . $app_id . '/lib/handlers/' . $event_prefix . "." . $name . ".handler.php"; if (!file_exists($file_path)) { continue; } wa($app_id); include_once $file_path; $class_name = $name; if (strpos($name, '.') !== false) { $class_name = strtok($class_name, '.') . ucfirst(strtok('')); } $class_name = $app_id . ucfirst($event_prefix) . ucfirst($class_name) . "Handler"; /** * @var $handler waEventHandler */ $handler = new $class_name(); try { $r = $handler->execute($params); if ($r !== null) { $result[$app_id] = $r; } } catch (Exception $e) { waLog::log('Event handling error in ' . $file_path . ': ' . $e->getMessage()); } } } if (isset(self::$handlers['plugins'][$event_app_id][$name])) { $plugins = $event_system->getConfig()->getPlugins(); foreach (self::$handlers['plugins'][$event_app_id][$name] as $plugin_id => $method) { if (!isset($plugins[$plugin_id])) { continue; } $plugin = $plugins[$plugin_id]; self::pushActivePlugin($plugin_id, $event_prefix); $class_name = $event_app_id . ucfirst($plugin_id) . 'Plugin'; try { $class = new $class_name($plugin); // Load plugin locale if it exists $locale_path = $this->getAppPath('plugins/' . $plugin_id . '/locale', $event_app_id); if (is_dir($locale_path)) { waLocale::load($this->getLocale(), $locale_path, self::getActiveLocaleDomain(), false); } if (method_exists($class, $method) && null !== ($r = $class->{$method}($params))) { if ($array_keys && is_array($r)) { foreach ($array_keys as $k) { if (!isset($r[$k])) { $r[$k] = ''; } } } $result[$plugin_id . '-plugin'] = $r; } } catch (Exception $e) { waLog::log('Event handling error in ' . $class_name . '->' . $name . '(): ' . $e->getMessage()); } self::popActivePlugin(); } } return $result; }
/** * Called when something went badly wrong so that current Runner should not continue, * (at least should immidiately notify a developer if in debug mode). * Still, not badly enough yet to break the whole long action process. */ protected function runnerFatalWarning($msg) { if (waSystemConfig::isDebug()) { // In debug mode, better to fail fast. throw new waException($msg); } else { waLog::log('waLongActionController (' . get_class($this) . '): ' . $msg); } }
function execute() { $update_ids = waRequest::get('app_id'); if ($update_ids && is_array($update_ids)) { ob_start(); $app_ids = array(); $plugins_ids = array(); $vendors = array(); foreach ($update_ids as $app_id => &$info) { if (!is_array($info)) { if (strpos($info, ':') === false) { $vendor = $info; $edition = ''; } else { list($vendor, $edition) = explode(':', $info, 2); } $app_ids[$app_id] = array('vendor' => $info, 'slug' => $app_id); } else { if (isset($info['slug'])) { $app_id = $info['slug']; } $app_ids[$app_id] = $info; } $vendors[] = $info['vendor']; unset($info); } $vendors = array_unique($vendors); $model = new waAppSettingsModel(); $license = $model->get('webasyst', 'license', false); $locale = wa()->getLocale(); try { $log_level = waSystemConfig::isDebug() ? waInstaller::LOG_DEBUG : waInstaller::LOG_WARNING; $thread_id = $this->getRequest()->request('thread_id', false); $updater = new waInstaller($log_level, $thread_id); $this->getStorage()->close(); $updater->init(); $apps = new waInstallerApps($license, $locale, false); $app = $this->getApp(); if (isset($app_ids[$app]) || true) { $system_list = $apps->getSystemList(); } if (isset($app_ids[$app])) { #update system items foreach ($system_list as $target => $item) { if (empty($item['subject'])) { $this->add(!empty($item['target']) ? $item['target'] : $item['slug'], $item); } } } foreach ($system_list as $target => $item) { if (!empty($item['subject']) && $item['subject'] == 'systemplugins' && isset($app_ids[$item['slug']])) { $this->add(!empty($item['target']) ? $item['target'] : $item['slug'], $item, $item['slug']); unset($app_ids[$item['slug']]); } } $app_list = $apps->getApplicationsList(false, $vendors, wa()->getDataPath('images', true)); $model->ping(); $this->pass = count($this->urls) || count($app_ids) > 1 ? true : false; $added = true; $execute_actions = array(waInstallerApps::ACTION_INSTALL, waInstallerApps::ACTION_CRITICAL_UPDATE, waInstallerApps::ACTION_UPDATE); while ($app_ids && $added) { $added = false; foreach ($app_list as &$info) { $app_id = $info['slug']; if ($app_id == 'installer') { $info['name'] = _w('Webasyst Framework'); } if (isset($app_ids[$app_id]) && installerHelper::equals($app_ids[$app_id], $info)) { $target = 'wa-apps/' . $app_id; $info['subject'] = 'app'; $this->add($target, $info, $app_id); unset($app_ids[$app_id]); } if (isset($info['extras']) && is_array($info['extras'])) { foreach ($info['extras'] as $subject => $extras) { foreach ($extras as $extras_id => $extras_info) { $extras_id = $app_id . '/' . $subject . '/' . $extras_id; if (isset($app_ids[$extras_id]) && installerHelper::equals($app_ids[$extras_id], $extras_info)) { if (!empty($app_ids[$extras_id]['dependent']) && (empty($extras_info['action']) || !in_array($extras_info['action'], $execute_actions))) { continue; } $target = 'wa-apps/' . $extras_id; $extras_info['subject'] = 'app_' . $subject; $this->add($target, $extras_info, $extras_info['slug']); if ($extras_info['dependency']) { foreach ($extras_info['dependency'] as $dependency) { $app_ids[$dependency] = $app_ids[$extras_id]; $app_ids[$dependency]['slug'] = $dependency; $app_ids[$dependency]['dependent'] = $target; $added = true; } } if ($subject == 'themes') { if (!empty($extras_info['current']['parent_theme_id'])) { $parent_id = $extras_info['current']['parent_theme_id']; $parent_app_id = $app_id; if (strpos($parent_id, ':')) { list($parent_app_id, $parent_id) = explode(':', $parent_id); } $dependency = "{$parent_app_id}/{$subject}/{$parent_id}"; $app_ids[$dependency] = $app_ids[$extras_id]; $app_ids[$dependency]['slug'] = $dependency; $app_ids[$dependency]['dependent'] = $target; $added = true; } } unset($app_ids[$extras_id]); } } } } } unset($info); } $storage = wa()->getStorage(); $storage->close(); $result_urls = $updater->update($this->urls); if (waRequest::get('install')) { $model->ping(); $user = $this->getUser(); $set_rights = false; if (!$user->isAdmin()) { $set_rights = true; } foreach ($this->urls as $target => $url) { //TODO workaround exceptions if ((!isset($url['skipped']) || !$url['skipped']) && preg_match('@^wa-apps@', $target)) { $apps->installWebAsystItem($url['slug'], null, isset($url['edition']) ? $url['edition'] : true); if ($set_rights) { $user->setRight($url['slug'], 'backend', 2); } } } } $secure_properties = array('archive', 'source', 'backup', 'md5', 'extract_path'); foreach ($result_urls as &$result_url) { foreach ($secure_properties as $property) { if (isset($result_url[$property])) { unset($result_url[$property]); } } unset($result_url); } $this->response['sources'] = $result_urls; $this->response['current_state'] = $updater->getState(); $this->response['state'] = $updater->getFullState(waRequest::get('mode', 'apps')); //cleanup cache //waFiles::delete(wa()->getAppCachePath(null, false), true); $path_cache = waConfig::get('wa_path_cache'); waFiles::delete($path_cache, true); waFiles::protect($path_cache); $root_path = waConfig::get('wa_path_root'); foreach ($this->urls as $url) { if (!isset($url['skipped']) || !$url['skipped']) { $path_cache = $root_path . '/' . $url['target'] . '/js/compiled'; waFiles::delete($path_cache, true); } } $model->ping(); $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'); } }
<?php if (!isset($argc)) { die("Run from CLI only!"); } require_once dirname(__FILE__) . '/../wa-config/SystemConfig.class.php'; if (count($argv) < 3) { die("Use\r\n" . realpath(dirname(__FILE__) . '/../') . "/cli.php APP CLASS PARAMS\r\n"); } try { $config = new SystemConfig('cli'); waSystem::getInstance(null, $config)->dispatchCli($argv); } catch (Exception $e) { waLog::log($e, "cli.log"); if (waSystemConfig::isDebug()) { echo $e; } }