本文整理汇总了PHP中Q::compareVersion方法的典型用法代码示例。如果您正苦于以下问题:PHP Q::compareVersion方法的具体用法?PHP Q::compareVersion怎么用?PHP Q::compareVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Q
的用法示例。
在下文中一共展示了Q::compareVersion方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: split
//.........这里部分代码省略.........
Q_Config::merge(array('Db' => array('connections' => array($connection => array("shards" => array(), "indexes" => array($table => array("fields" => $fields, "partition" => $split_mapped ? array($shard => '') : array($shard))))))));
$shard_name = '';
}
// get partition information
if (!($partition = Q_Config::get('Db', 'connections', $connection, 'indexes', $table, 'partition', false))) {
echo "Upps, cannot get shards partitioning\n";
return false;
}
// weather main config is mapped or not
// also $points contains the partitioning array without mapping
$points = ($mapped = array_keys($partition) !== range(0, count($partition) - 1)) ? array_keys($partition) : $partition;
$i = array_search($shard, $points);
$next = isset($points[++$i]) ? $points[$i] : null;
$fields = Q_Config::expect('Db', 'connections', $connection, 'indexes', $table, 'fields');
// now $shard and $next contain boundaries for data to split
// $points contain partitioning array without mapping - array
// $parts contains split parts (shards) definition - array or object ($split_mapped)
// $partition contains current partitioning - array or object ($mapped)
// $fields contains field names and hashes
// time to calculate new split point(s)
if (!isset($shard_name)) {
$shard_name = $mapped ? $partition[$shard] : $shard;
}
$shard_db = $class::db();
$pdo = $shard_db->reallyConnect($shard_name);
$shard_table = $class::table();
$shard_table = str_replace('{$dbname}', $shard_db->dbname, $shard_table);
$shard_table = str_replace('{$prefix}', $shard_db->prefix, $shard_table);
// verify if current shard is updated to latest version
$current_version = $shard_db->select('version', "{$shard_db->prefix}Q_plugin")->where(array("plugin" => $plugin))->fetchAll(PDO::FETCH_ASSOC);
if (!empty($current_version)) {
$current_version = $current_version[0]['version'];
$version = Q_Config::get('Q', "pluginInfo", $plugin, 'version', null);
if (Q::compareVersion($current_version, $version) < 0) {
echo "Please, update plugin '{$plugin}' to version '{$version}' (currently {$current_version})\n";
return false;
}
} else {
echo "Cannot get installed version of plugin '{$plugin}'\n";
return false;
}
// We'll limit search with shard boundaries using latin1 string comparison
$lower = join(explode('.', $shard));
$upper = isset($next) ? join(explode('.', $next)) : null;
$normalize = false;
$where = $group = $order = array();
foreach (array_keys($fields) as $i => $field) {
$hash = !empty($fields[$field]) ? $fields[$field] : 'md5';
$part = explode('%', $hash);
$normalize = $normalize || ($hash = strtoupper($part[0])) === 'NORMALIZE';
$len = isset($part[1]) ? $part[1] : Db_Query::HASH_LEN;
$group[] = $field;
$order[] = "CAST({$hash}({$field}) AS CHAR({$len}))";
}
// if any field uses 'normalize' hash
// the original shard shall have MySQL NORMALIZE() function defined
// MySQL version of NORMALIZE handles only 255 chars and does not add md5 hash
// (see Db_Utils::normalize)
if ($normalize) {
try {
$pdo->exec("DROP FUNCTION IF EXISTS NORMALIZE;");
$pdo->exec("CREATE FUNCTION NORMALIZE(s CHAR(255))\n\t\t\t\t\t\tRETURNS CHAR(255) DETERMINISTIC\n\t\t\t\t\t\tBEGIN\n\t\t\t\t\t \tDECLARE res CHAR(255) DEFAULT '';\n\t\t\t\t\t \t\tDECLARE t CHAR(1);\n\t\t\t\t\t \tWHILE LENGTH(s) > 0 DO\n\t\t\t\t\t \tSET t = LOWER(LEFT(s, 1));\n\t\t\t\t\t \t SET s = SUBSTRING(s FROM 2);\n\t\t\t\t\t \tIF t REGEXP '[^A-Za-z0-9]' THEN\n\t\t\t\t\t \tSET t = '_';\n\t\t\t\t\t \tEND IF;\n\t\t\t\t\t \tSET res = CONCAT(res, t);\n\t\t\t\t\t \tEND WHILE;\n\t\t\t\t\t \tRETURN res;\n\t\t\t\t\t\tEND");
} catch (Exception $e) {
//echo "ERROR: {$e->getMessage()}\n";
echo "Please, make sure that db user for shard '{$shard_name}' has 'CREATE ROUTINE' permission\n";
return false;
示例2: checkRequirementsApp
/**
* @method checkRequirementsApp
* @static
* @throws {Q_Exception_AppRequirement}
* @throws {Q_Exception_AppRequirementVersion}
*/
static function checkRequirementsApp()
{
$title = Q_Config::expect('Q', 'app');
$required = Q_Config::get('Q', 'appInfo', 'requires', array());
$local = Q_Config::get('Q', 'pluginLocal', array());
$local['Q'] = array('version' => Q_VERSION, 'compatible' => Q_VERSION);
foreach ($required as $required_plugin => $required_version) {
if (!isset($local[$required_plugin])) {
throw new Q_Exception_AppRequirement(array('plugin' => $required_plugin, 'version' => $required_version, 'by' => $title));
}
$installed_version = isset($local[$required_plugin]['version']) ? $local[$required_plugin]['version'] : 0;
$compatible_version = isset($local[$required_plugin]['compatible']) ? $local[$required_plugin]['compatible'] : 0;
if (Q::compareVersion($installed_version, $required_version) < 0) {
throw new Q_Exception_AppRequirementVersion(array('plugin' => $required_plugin, 'version' => $required_version, 'by' => $title, 'installed' => $installed_version, 'compatible' => $compatible_version));
}
if (Q::compareVersion($compatible_version, $required_version) > 0) {
throw new Q_Exception_AppRequirementVersion(array('plugin' => $required_plugin, 'version' => $required_version, 'by' => $title, 'installed' => $installed_version, 'compatible' => $compatible_version));
}
}
}
示例3: installPlugin
/**
* @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::compareVersion($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;
Q_Utils::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');
}