コード例 #1
0
 /**
  * Invoke the controller
  *
  * Always use this method, not control(), to invoke the controller.
  * @TODO show get 500 error template on Exception
  * (if debugging is true, pass the exception details to the 500 template)
  */
 public function go()
 {
     try {
         $this->initalizeApp();
         // are we in need of a database migration?
         $classname = get_class($this);
         if ($classname != 'InstallerController' && $classname != 'BackupController' && UpgradeDatabaseController::isUpgrading($this->isAdmin(), $classname)) {
             $this->setViewTemplate('install.upgradeneeded.tpl');
             $this->disableCaching();
             $option_dao = DAOFactory::getDAO('OptionDAO');
             $option_dao->clearSessionData(OptionDAO::APP_OPTIONS);
             return $this->generateView();
         } else {
             $results = $this->control();
             if ($this->profiler_enabled && !isset($this->json_data) && strpos($this->content_type, 'text/javascript') === false && strpos($this->content_type, 'text/csv') === false) {
                 $end_time = microtime(true);
                 $total_time = $end_time - $this->start_time;
                 $profiler = Profiler::getInstance();
                 $this->disableCaching();
                 $profiler->add($total_time, "total page execution time, running " . $profiler->total_queries . " queries.");
                 $this->setViewTemplate('_profiler.tpl');
                 $this->addToView('profile_items', $profiler->getProfile());
                 return $results . $this->generateView();
             } else {
                 return $results;
             }
         }
     } catch (ControllerAuthException $e) {
         Utils::setDefaultTimezonePHPini();
         $this->setErrorTemplateState();
         $this->addToView('error_type', get_class($e));
         $config = Config::getInstance();
         $message = 'You must <a href="' . $config->getValue('site_root_path') . 'session/login.php">log in</a> to do this.';
         $this->addErrorMessage($message, null, true);
         return $this->generateView();
     } catch (ConfigurationException $e) {
         $this->setErrorTemplateState();
         $this->addToView('error_type', get_class($e));
         $message = 'ThinkUp\'s configuration file does not exist! Try <a href="' . Utils::getSiteRootPathFromFileSystem() . 'install/">installing ThinkUp.</a>';
         $this->addErrorMessage($message, null, true);
         return $this->generateView();
     } catch (Exception $e) {
         Utils::setDefaultTimezonePHPini();
         $this->setErrorTemplateState();
         $this->addToView('error_type', get_class($e));
         $disable_xss = false;
         // if we are an installer exception, don't filter XSS, we have markup, and we trust this content
         if (get_class($e) == 'InstallerException') {
             $disable_xss = true;
         }
         $this->addErrorMessage($e->getMessage(), null, $disable_xss);
         return $this->generateView();
     }
 }
コード例 #2
0
 /**
  * Determine if ThinkUp needs to show the upgrading page.
  * @param bool Is the current user an admin
  * @param str The calling classname
  * @return bool Whether or not we need to show the upgrade page
  */
 public static function isUpgrading($is_admin, $class_name)
 {
     $config = Config::getInstance();
     $status = false;
     $db_version = UpgradeDatabaseController::getCurrentDBVersion($config->getValue('cache_pages'));
     if (version_compare($db_version, $config->getValue('THINKUP_VERSION'), '<')) {
         if ($class_name != 'UpgradeDatabaseController') {
             $status = true;
         } else {
             if (!$is_admin && !isset($_GET['upgrade_token'])) {
                 $status = true;
             }
         }
         if ($status == true) {
             self::generateUpgradeToken();
         }
     }
     return $status;
 }
コード例 #3
0
 /**
  * Runs registered plugins' crawl function.
  *
  * About crawler exclusivity (mutex usage):
  * When launched by an admin, no other user, admin or not, will be able to launch a crawl until this one is done.
  * When launched by a non-admin, we first check that no admin run is under way, and if that's the case,
  * we launch a crawl for the current user only.
  * No user will be able to launch two crawls in parallel, but different non-admin users crawls can run in parallel.
  * @throws UnauthorizedUserException If user is not logged in
  * @throws CrawlerLockedException If a crawl is already in progress
  * @throws InstallerException If ThinkUp is in the midst of a database upgrade
  */
 public function runRegisteredPluginsCrawl()
 {
     if (!Session::isLoggedIn()) {
         throw new UnauthorizedUserException('You need a valid session to launch the crawler.');
     }
     $mutex_dao = DAOFactory::getDAO('MutexDAO');
     $owner_dao = DAOFactory::getDAO('OwnerDAO');
     $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
     if (empty($owner)) {
         throw new UnauthorizedUserException('You need a valid session to launch the crawler.');
     }
     // are we in an upgrading state
     if (UpgradeDatabaseController::isUpgrading(true, 'Crawler')) {
         throw new InstallerException("ThinkUp needs a database migration, so we are unable to run the crawler.");
     }
     $global_mutex_name = self::GLOBAL_MUTEX;
     // Everyone needs to check the global mutex
     $lock_successful = 1;
     $mutex_dao->getMutex($global_mutex_name);
     // 1
     if ($lock_successful) {
         // Global mutex was free, which means no admin crawls are under way
         if ($owner->is_admin) {
             // Nothing more needs to be done, since admins use the global mutex
             $mutex_name = $global_mutex_name;
         } else {
             // User is a non-admin; let's use a user mutex.
             $mutex_name = 'crawler-' . $owner->id;
             $lock_successful = $mutex_dao->getMutex($mutex_name);
             $mutex_dao->releaseMutex($global_mutex_name);
         }
     }
     if ($lock_successful) {
         $this->emitObjectFunction('crawl');
         $mutex_dao->releaseMutex($mutex_name);
         //clear cache so that insight stream updates
         $v_mgr = new ViewManager();
         $v_mgr->clear_all_cache();
     } else {
         throw new CrawlerLockedException("Error starting crawler; another crawl is already in progress.");
     }
 }
コード例 #4
0
 public function testProcessMigrationsDifferentPrefix()
 {
     $config = Config::getInstance();
     $old_table_prefix = $config->getValue('table_prefix');
     $config->setValue('table_prefix', 'new_prefix_');
     $stmt = $this->pdo->query("show tables");
     $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     //var_dump($data);
     foreach ($data as $table) {
         foreach ($table as $key => $value) {
             $new_value = preg_replace("/^" . $old_table_prefix . "/", " new_prefix_", $value);
             $sql = "RENAME TABLE {$value} TO {$new_value}";
             $this->pdo->query($sql);
         }
     }
     $this->simulateLogin('*****@*****.**', true);
     $controller = new UpgradeDatabaseController(true);
     $this->migrationFiles(1);
     $_GET['migration_index'] = 1;
     $results = $controller->go();
     $obj = json_decode($results);
     $this->assertTrue($obj->processed);
     $updated_file = file_get_contents($this->test_migrations[0]);
     $updated_file = preg_replace('/\\-\\-.*/', '', $updated_file);
     $updated_file = str_replace('tu_', 'new_prefix_', $updated_file);
     $this->debug($obj->sql);
     $this->assertEqual($obj->sql, $updated_file);
     $this->assertFalse(strrpos($obj->sql, 'tu_'));
     $sql = "show tables like 'new_prefix_test1'";
     $stmt = $this->pdo->query($sql);
     $data = $stmt->fetch();
     $this->assertEqual($data[0], 'new_prefix_test1');
     $sql = 'select * from new_prefix_test1';
     $stmt = $this->pdo->query($sql);
     $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $this->assertEqual(count($data), 3);
 }
コード例 #5
0
ファイル: upgrade.php プロジェクト: dgw/ThinkUp
             putenv('BACKUP_VERBOSE=true');
             $backup_dao = DAOFactory::getDAO('BackupDAO');
             print "\nExporting data to: {$filename}\n\n";
             $backup_dao->export($filename);
             print "\nBackup completed.\n\n";
         }
     }
 }
 // run updates...
 // get migrations we need to run...
 if (!$no_version) {
     print "\nUpgrading Thinkup to version {$thinkup_db_version}...\n\n";
 }
 $upgrade_start_time = microtime(true);
 putenv('CLI_BACKUP=true');
 $upgrade_ctl = new UpgradeDatabaseController();
 $migrations = $upgrade_ctl->getMigrationList($db_version, $no_version);
 $install_dao = DAOFactory::getDAO('InstallerDAO');
 if ($no_version && count($migrations) > 0) {
     $s = count($migrations) > 1 ? 's' : '';
     print "\nFound " . count($migrations) . " migration" . $s . " to process...\n";
 }
 foreach ($migrations as $migration) {
     if ($no_version) {
         print "\n  Running migration with file " . $migration['filename'] . "\n";
     } else {
         print "\n  Running migration " . $migration['version'] . "\n";
     }
     $sql = preg_replace('/\\-\\-.*/', '', $migration['sql']);
     $install_dao->runMigrationSQL($sql, $migration['new_migration'], $migration['filename']);
 }
コード例 #6
0
 public function testLoadBackupViewCLIWarn()
 {
     $this->simulateLogin('*****@*****.**', true);
     $controller = new BackupController(true);
     $results = $controller->control();
     $this->assertPattern('/Back Up Your ThinkUp Data/', $results);
     $v_mgr = $controller->getViewManager();
     $this->assertNull($v_mgr->getTemplateDataItem('high_table_row_count'));
     // table row counts are bad
     $old_count = UpgradeDatabaseController::$WARN_TABLE_ROW_COUNT;
     UpgradeDatabaseController::$WARN_TABLE_ROW_COUNT = 2;
     $results = $controller->control();
     $this->assertPattern('/we recommend that you use the/', $results);
     $table_counts = $v_mgr->getTemplateDataItem('high_table_row_count');
     $this->assertNotNull($table_counts);
     $this->assertNotNull(3, $table_counts['count']);
     // tu_plugins, defaults to three
     UpgradeDatabaseController::$WARN_TABLE_ROW_COUNT = $old_count;
 }
コード例 #7
0
ファイル: upgrade-database.php プロジェクト: dgw/ThinkUp
/**
 *
 * ThinkUp/webapp/install/upgrade-database.php
 *
 * Copyright (c) 2009-2013 Mark Wilkie
 *
 * LICENSE:
 *
 * This file is part of ThinkUp (http://thinkup.com).
 *
 * ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
 * later version.
 *
 * ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with ThinkUp.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 *
 * @license http://www.gnu.org/licenses/gpl.html
 * @copyright 2009-2013 Mark Wilkie
 * @author Mark Wilkie <mwilkie[at]gmail[dot]com>
 *
 */
chdir("..");
require_once 'init.php';
$controller = new UpgradeDatabaseController();
echo $controller->go();