예제 #1
0
 /**
  * @method registerErrorHandler
  * @static
  */
 static function registerErrorHandler()
 {
     self::$prev_error_handler = set_error_handler(array('Q', 'errorHandler'));
 }
예제 #2
0
require Q_CLASSES_DIR . DS . 'Q' . DS . 'Exception' . DS . 'PhpError.php';
require Q_CLASSES_DIR . DS . 'Db.php';
require Q_CLASSES_DIR . DS . 'Db' . DS . 'Expression.php';
require Q_CLASSES_DIR . DS . 'Db' . DS . 'Query.php';
//
// Set things up
//
Q::milliseconds();
Q_Bootstrap::registerShutdownFunction();
Q_Bootstrap::setDefaultTimezone();
Q_Bootstrap::setIncludePath();
Q_Bootstrap::registerAutoload();
Q_Bootstrap::defineFunctions();
Q_Bootstrap::registerExceptionHandler();
Q_Bootstrap::registerErrorHandler();
Q_Bootstrap::revertSlashes();
Q_Bootstrap::configure();
Q_Bootstrap::alertAboutLocalConfiguration();
Q_Bootstrap::setDefaultTimezone();
Q_Bootstrap::setResponseBuffered();
Q_Bootstrap::setUrls();
Q_Response::setIgnoreUserAbort();
if (defined('APP_WEB_DIR')) {
    Q_Bootstrap::addAlias();
    Q_Request::baseUrl();
}
Q::$bootstrapped = true;
//
// Give the project a chance to load aggregated files, etc.
//
Q::event('Q/init');
예제 #3
0
    $plugins = Q_Config::get('Q', 'plugins', array());
    if (!in_array("Q", $plugins)) {
        array_unshift($plugins, "Q");
    }
}
Q_Plugin::checkPermissions(APP_FILES_DIR, array_merge($options, array('deep' => true)));
foreach ($plugins as $plugin) {
    $cons = Q_Config::get('Q', 'pluginInfo', $plugin, 'connections', array());
    foreach ($cons as $con) {
        if (empty($options['sql'][$con])) {
            $options['sql'][$con] = array('enabled' => true);
        }
    }
    Q_Plugin::installPlugin($plugin, $options);
    ++$Q_Bootstrap_config_plugin_limit;
    Q_Bootstrap::configure(true);
}
if (!$noapp) {
    // if application is installed/updated, it's schema is always installed/updated
    $cons = Q_Config::get('Q', 'appInfo', 'connections', array());
    foreach ($cons as $con) {
        if (empty($options['sql'][$con])) {
            $options['sql'][$con] = array('enabled' => true);
        }
    }
    Q_Plugin::installApp($options);
    if (empty($noInit) && file_exists($LOCAL_DIR . DS . 'scripts' . DS . 'init.php')) {
        echo 'Running initialization script' . PHP_EOL;
        include $LOCAL_DIR . DS . 'scripts' . DS . 'init.php';
    }
}
예제 #4
0
 /**
  * @method installPlugin
  * @static
  * @param {string} $plugin_name
  * @param {array} $options
  * @throws {Exception}
  */
 static function installPlugin($plugin_name, $options)
 {
     set_time_limit(Q_Config::expect('Q', 'install', 'timeLimit'));
     // Connect Qbix platform if it's not already connected
     self::prepare();
     $app_dir = APP_DIR;
     $plugin_dir = Q_PLUGINS_DIR . DS . $plugin_name;
     $app_web_plugins_dir = APP_WEB_DIR . DS . 'plugins';
     echo "Installing plugin '{$plugin_name}' into '{$app_dir}'" . PHP_EOL;
     // Do we even have such a plugin?
     if (!is_dir($plugin_dir)) {
         throw new Exception("Plugin '{$plugin_name}' not found in " . Q_PLUGINS_DIR);
     }
     // Ensure that the plugin has config.json
     if (!file_exists($plugin_conf_file = $plugin_dir . DS . 'config' . DS . 'plugin.json')) {
         throw new Exception("Could not load plugin's config. Check {$plugin_conf_file}");
     }
     $files_dir = $plugin_dir . DS . 'files';
     $app_plugins_file = APP_LOCAL_DIR . DS . 'plugins.json';
     // Check access to $app_web_plugins_dir
     if (!file_exists($app_web_plugins_dir)) {
         if (!@mkdir($app_web_plugins_dir, 0755, true)) {
             throw new Exception("Could not create {$app_web_plugins_dir}");
         }
     }
     if (!is_dir($app_web_plugins_dir)) {
         throw new Exception("{$app_web_plugins_dir} exists, but is not a directory");
     } elseif (!is_writable($app_web_plugins_dir)) {
         throw new Exception("Can not write to {$app_web_plugins_dir}");
     }
     // Check access to $app_plugins_file
     if (file_exists($app_plugins_file) && !is_writable($app_plugins_file)) {
         throw new Exception("Can not write to {$app_plugins_file}");
     } elseif (!file_exists($app_plugins_file) && !is_writable(dirname($app_plugins_file))) {
         throw new Exception("Can not write to " . dirname($app_plugins_file));
     }
     // Check access to $files_dir
     if (!file_exists($files_dir)) {
         if (!@mkdir($files_dir, $options['dirmode'], true)) {
             throw new Exception("Could not create {$files_dir}");
         }
     }
     // Do we now have plugin's config?
     if (Q_Config::get('Q', 'pluginInfo', $plugin_name, 'version', null) == null) {
         throw new Exception("Could not identify plugin version. Check {$plugin_conf_file}");
     }
     $plugin_conf = Q_Config::get('Q', 'pluginInfo', $plugin_name, null);
     $plugin_version = $plugin_conf['version'];
     if (file_exists($app_plugins_file)) {
         Q_Config::load($app_plugins_file, true);
     }
     //  Do we already have this plugin installed for this app?
     // Check requirements for plugin (will throw exceptions if they aren't met)
     if (!isset($options['noreq']) || !$options['noreq']) {
         echo "Checking requirements" . PHP_EOL;
         Q_Bootstrap::checkRequirements(array($plugin_name));
     }
     //  Checking LOCAL plugin version in plugins.json file
     if (($version_installed = Q_Config::get('Q', 'pluginLocal', $plugin_name, 'version', null)) != null) {
         //We have this plugin installed
         echo "Plugin '{$plugin_name}' (version: {$version_installed}) is already installed" . PHP_EOL;
         if (Q::compare_version($version_installed, $plugin_version) < 0) {
             echo "Upgrading '{$plugin_name}' to version: {$plugin_version}" . PHP_EOL;
         }
     }
     // Check and fix permissions
     self::checkPermissions($files_dir, $options);
     if (isset($plugin_conf['permissions'])) {
         foreach ($plugin_conf['permissions'] as $perm) {
             self::checkPermissions($files_dir . DS . $perm, $options);
         }
     }
     // Symbolic links
     echo 'Creating symbolic links' . PHP_EOL;
     self::symlink($plugin_dir . DS . 'web', $app_web_plugins_dir . DS . $plugin_name);
     //  Checking if schema update is requested and updating database version
     $connections = Q_Config::get('Q', 'pluginInfo', $plugin_name, 'connections', array());
     foreach ($connections as $connection) {
         self::installSchema(Q_PLUGINS_DIR . DS . $plugin_name, $plugin_name, 'plugin', $connection, $options);
     }
     // Push plugin name into Q/plugins array
     if (!in_array($plugin_name, $current_plugins = Q_Config::get('Q', 'plugins', array()))) {
         $current_plugins[] = $plugin_name;
         Q_Config::set('Q', 'plugins', $current_plugins);
         //TODO: When do we save Q/plugins to disk?
     }
     // Save info about plugin
     echo 'Registering plugin' . PHP_EOL;
     Q_Config::set('Q', 'pluginLocal', $plugin_name, $plugin_conf);
     Q_Config::save($app_plugins_file, array('Q', 'pluginLocal'));
     echo Q_Utils::colored("Plugin '{$plugin_name}' successfully installed" . PHP_EOL, 'green');
 }