本文整理汇总了PHP中module::available方法的典型用法代码示例。如果您正苦于以下问题:PHP module::available方法的具体用法?PHP module::available怎么用?PHP module::available使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类module
的用法示例。
在下文中一共展示了module::available方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upgrade
public function upgrade()
{
if (php_sapi_name() == "cli") {
// @todo this may screw up some module installers, but we don't have a better answer at
// this time.
$_SERVER["HTTP_HOST"] = "example.com";
} else {
if (!user::active()->admin && !Session::instance()->get("can_upgrade", false)) {
access::forbidden();
}
}
// Upgrade gallery and user first
module::install("gallery");
module::install("user");
// Then upgrade the rest
foreach (module::available() as $id => $module) {
if ($id == "gallery") {
continue;
}
if ($module->active && $module->code_version != $module->version) {
module::install($id);
}
}
if (php_sapi_name() == "cli") {
print "Upgrade complete\n";
} else {
url::redirect("upgrader?done=1");
}
}
示例2: save
public function save()
{
access::verify_csrf();
$changes->activate = array();
$changes->deactivate = array();
$activated_names = array();
$deactivated_names = array();
foreach (module::available() as $module_name => $info) {
if ($info->locked) {
continue;
}
$desired = $this->input->post($module_name) == 1;
if ($info->active && !$desired && module::is_active($module_name)) {
$changes->deactivate[] = $module_name;
$deactivated_names[] = $info->name;
module::deactivate($module_name);
} else {
if (!$info->active && $desired && !module::is_active($module_name)) {
$changes->activate[] = $module_name;
$activated_names[] = $info->name;
module::install($module_name);
module::activate($module_name);
}
}
}
module::event("module_change", $changes);
// @todo this type of collation is questionable from a i18n perspective
if ($activated_names) {
message::success(t("Activated: %names", array("names" => join(", ", $activated_names))));
}
if ($deactivated_names) {
message::success(t("Deactivated: %names", array("names" => join(", ", $deactivated_names))));
}
url::redirect("admin/modules");
}
示例3: index
/**
* Builds the backend information for the Module Updates page.
*
* Builds an array of data containing the needed information about an installed copy of Gallery3
* to determine if versions stored in the GitHub are newer.
*
* List ID: The name of the folder the module resides in (obtained from module::available)
* name: The given name of the module (obtained from module::available)
* locked: If the module is considered locked by Gallery (obtained from module::available)
* code_version: The version of the module in the modules directory (obtained from module::available)
* active: If the module is installed and enabled (obtained from module::available)
* version: The version installed and running (obtained from module::available)
* description: The description of the module (obtained from module::available)
* remote_version: The version of the code on GitHub (obtained from get_remote_module_version)
* remote_server: The server the remote version is on (obtained from get_remote_module_version)
* font_color: The color to display the update in depending on its status
*
* @author brentil <forums@inner-ninja.com>
*/
public function index()
{
$view = new Admin_View("admin.html");
$view->page_title = t("Gallery 3 :: Manage Module Updates");
$view->content = new View("admin_moduleupdates.html");
$all_modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
foreach (module::available() as $this_module_name => $module_info) {
list($remote_version, $remote_server) = $this->get_remote_module_version($this_module_name);
$font_color = "black";
if ($remote_version == "DNE") {
$font_color = "blue";
} else {
if ($remote_version < $module_info->code_version) {
$font_color = "green";
} else {
if ($remote_version > $module_info->code_version) {
$font_color = "red";
}
}
}
$all_modules->{$this_module_name} = array("name" => $module_info->name, "locked" => $module_info->locked, "code_version" => $module_info->code_version, "active" => $module_info->active, "version" => $module_info->version, "description" => $module_info->description, "remote_version" => $remote_version, "remote_server" => $remote_server, "font_color" => $font_color);
}
$view->content->vars = $all_modules;
print $view;
}
示例4: upgrade
public function upgrade()
{
if (php_sapi_name() == "cli") {
// @todo this may screw up some module installers, but we don't have a better answer at
// this time.
$_SERVER["HTTP_HOST"] = "example.com";
} else {
if (!identity::active_user()->admin && !Session::instance()->get("can_upgrade", false)) {
access::forbidden();
}
try {
access::verify_csrf();
} catch (Exception $e) {
url::redirect("upgrader");
}
}
$available = module::available();
// Upgrade gallery first
$gallery = $available["gallery"];
if ($gallery->code_version != $gallery->version) {
module::upgrade("gallery");
module::activate("gallery");
}
// Then upgrade the rest
$failed = array();
foreach (module::available() as $id => $module) {
if ($id == "gallery") {
continue;
}
if ($module->active && $module->code_version != $module->version) {
try {
module::upgrade($id);
} catch (Exception $e) {
// @todo assume it's MODULE_FAILED_TO_UPGRADE for now
$failed[] = $id;
}
}
}
// If the upgrade failed, this will get recreated
site_status::clear("upgrade_now");
// Clear any upgrade check strings, we are probably up to date.
site_status::clear("upgrade_checker");
if (php_sapi_name() == "cli") {
if ($failed) {
print "Upgrade completed ** WITH FAILURES **\n";
print "The following modules were not successfully upgraded:\n";
print " " . implode($failed, "\n ") . "\n";
print "Try getting newer versions or deactivating those modules\n";
} else {
print "Upgrade complete\n";
}
} else {
if ($failed) {
url::redirect("upgrader?failed=" . join(",", $failed));
} else {
url::redirect("upgrader");
}
}
}
示例5: providers
/**
* Return a list of installed Identity Drivers.
*
* @return boolean true if the driver supports updates; false if read only
*/
static function providers()
{
if (empty(self::$available)) {
$drivers = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
foreach (module::available() as $module_name => $module) {
if (file_exists(MODPATH . "{$module_name}/config/identity.php")) {
$drivers->{$module_name} = $module->description;
}
}
self::$available = $drivers;
}
return self::$available;
}
示例6: _do_save
private function _do_save()
{
$changes = new stdClass();
$changes->activate = array();
$changes->deactivate = array();
$activated_names = array();
$deactivated_names = array();
foreach (module::available() as $module_name => $info) {
if ($info->locked) {
continue;
}
try {
$desired = Input::instance()->post($module_name) == 1;
if ($info->active && !$desired && module::is_active($module_name)) {
module::deactivate($module_name);
$changes->deactivate[] = $module_name;
$deactivated_names[] = t($info->name);
} else {
if (!$info->active && $desired && !module::is_active($module_name)) {
if (module::is_installed($module_name)) {
module::upgrade($module_name);
} else {
module::install($module_name);
}
module::activate($module_name);
$changes->activate[] = $module_name;
$activated_names[] = t($info->name);
}
}
} catch (Exception $e) {
message::warning(t("An error occurred while installing the <b>%module_name</b> module", array("module_name" => $info->name)));
Kohana_Log::add("error", (string) $e);
}
}
module::event("module_change", $changes);
// If modules need upgrading, this will get recreated
site_status::clear("upgrade_now");
// @todo this type of collation is questionable from an i18n perspective
if ($activated_names) {
message::success(t("Activated: %names", array("names" => join(", ", $activated_names))));
}
if ($deactivated_names) {
message::success(t("Deactivated: %names", array("names" => join(", ", $deactivated_names))));
}
}
示例7: save
public function save()
{
foreach (module::available() as $module_name => $info) {
if ($info->locked) {
continue;
}
$desired = $this->input->post($module_name) == 1;
if ($info->installed && !$desired) {
module::uninstall($module_name);
message::success(t("Uninstalled %module_name module", array("module_name" => $info->name)));
} else {
if (!$info->installed && $desired) {
module::install($module_name);
message::success(t("Installed %module_name module", array("module_name" => $info->name)));
}
}
}
url::redirect("admin/modules");
}
示例8: _do_save
private function _do_save()
{
$changes->activate = array();
$changes->deactivate = array();
$activated_names = array();
$deactivated_names = array();
foreach (module::available() as $module_name => $info) {
if ($info->locked) {
continue;
}
try {
$desired = Input::instance()->post($module_name) == 1;
if ($info->active && !$desired && module::is_active($module_name)) {
module::deactivate($module_name);
$changes->deactivate[] = $module_name;
$deactivated_names[] = t($info->name);
} else {
if (!$info->active && $desired && !module::is_active($module_name)) {
if (module::is_installed($module_name)) {
module::upgrade($module_name);
} else {
module::install($module_name);
}
module::activate($module_name);
$changes->activate[] = $module_name;
$activated_names[] = t($info->name);
}
}
} catch (Exception $e) {
Kohana_Log::add("error", (string) $e);
}
}
module::event("module_change", $changes);
// @todo this type of collation is questionable from an i18n perspective
if ($activated_names) {
message::success(t("Activated: %names", array("names" => join(", ", $activated_names))));
}
if ($deactivated_names) {
message::success(t("Deactivated: %names", array("names" => join(", ", $deactivated_names))));
}
}
示例9: upgrade
/**
* Upgrade a module. This will call <module>_installer::upgrade(), which is responsible for
* modifying database tables, changing module variables and calling module::set_version().
* Note that after upgrading, the module must be activated before it is available for use.
* @param string $module_name
*/
static function upgrade($module_name)
{
$version_before = module::get_version($module_name);
$installer_class = "{$module_name}_installer";
$available = module::available();
if (class_exists($installer_class) && method_exists($installer_class, "upgrade")) {
call_user_func_array(array($installer_class, "upgrade"), array($version_before));
} else {
if (isset($available->{$module_name}->code_version)) {
module::set_version($module_name, $available->{$module_name}->code_version);
} else {
throw new Exception("@todo UNKNOWN_MODULE");
}
}
module::load_modules();
$version_after = module::get_version($module_name);
if ($version_before != $version_after) {
log::success("module", t("Upgraded module %module_name from %version_before to %version_after", array("module_name" => $module_name, "version_before" => $version_before, "version_after" => $version_after)));
}
if ($version_after != $available->{$module_name}->code_version) {
throw new Exception("@todo MODULE_FAILED_TO_UPGRADE");
}
}
示例10: index
function index()
{
if (!TEST_MODE) {
throw new Kohana_404_Exception();
}
// Force strict behavior to flush out bugs early
ini_set("display_errors", true);
error_reporting(-1);
// Jump through some hoops to satisfy the way that we check for the site_domain in
// config.php. We structure this such that the code in config will leave us with a
// site_domain of "." (for historical reasons)
// @todo: for tests, we should force the site_domain to something like example.com
$_SERVER["SCRIPT_FILENAME"] = "index.php";
$_SERVER["SCRIPT_NAME"] = "./index.php";
$config = Kohana_Config::instance();
$original_config = DOCROOT . "var/database.php";
$test_config = VARPATH . "database.php";
if (!file_exists($original_config)) {
print "Please copy kohana/config/database.php to {$original_config}.\n";
return;
} else {
copy($original_config, $test_config);
$db_config = Kohana::config('database');
if (empty($db_config['unit_test'])) {
$default = $db_config['default'];
$conn = $default['connection'];
$config->set('database.unit_test.benchmark', $default['benchmark']);
$config->set('database.unit_test.persistent', $default['persistent']);
$config->set('database.unit_test.connection.type', $conn['type']);
$config->set('database.unit_test.connection.user', $conn['user']);
$config->set('database.unit_test.connection.pass', $conn['pass']);
$config->set('database.unit_test.connection.host', $conn['host']);
$config->set('database.unit_test.connection.port', $conn['port']);
$config->set('database.unit_test.connection.socket', $conn['socket']);
$config->set('database.unit_test.connection.database', "{$conn['database']}_test");
$config->set('database.unit_test.character_set', $default['character_set']);
$config->set('database.unit_test.table_prefix', $default['table_prefix']);
$config->set('database.unit_test.object', $default['object']);
$config->set('database.unit_test.cache', $default['cache']);
$config->set('database.unit_test.escape', $default['escape']);
$db_config = Kohana::config('database');
}
if ($db_config['default']['connection']['database'] == $db_config['unit_test']['connection']['database']) {
print "Don't use the default database for your unit tests or you'll lose all your data.\n";
return;
}
try {
$db = Database::instance('unit_test');
$db->connect();
// Make this the default database for the rest of this run
Database::set_default_instance($db);
} catch (Exception $e) {
print "{$e->getMessage()}\n";
return;
}
}
try {
// Clean out the database
if ($tables = $db->list_tables()) {
foreach ($db->list_tables() as $table) {
$db->query("DROP TABLE {{$table}}");
}
}
// Clean out the filesystem. Note that this cleans out test/var/database.php, but that's ok
// because we technically don't need it anymore. If this is confusing, we could always
// arrange to preserve that one file.
@system("rm -rf test/var");
@mkdir('test/var/logs', 0777, true);
$active_modules = module::$active;
// Reset our caches
module::$modules = array();
module::$active = array();
module::$var_cache = array();
$db->clear_cache();
// Rest the cascading class path
$config->set("core", $config->load("core"));
// Install the active modules
// Force gallery and user to be installed first to resolve dependencies.
gallery_installer::install(true);
module::load_modules();
module::install("user");
module::activate("user");
$modules = $paths = array();
foreach (module::available() as $module_name => $unused) {
if (in_array($module_name, array("gallery", "user"))) {
$paths[] = MODPATH . "{$module_name}/tests";
continue;
}
if (file_exists($path = MODPATH . "{$module_name}/tests")) {
$paths[] = $path;
module::install($module_name);
module::activate($module_name);
}
}
$config->set('unit_test.paths', $paths);
// Trigger late-binding install actions (defined in gallery_event::user_login)
graphics::choose_default_toolkit();
$filter = count($_SERVER["argv"]) > 2 ? $_SERVER["argv"][2] : null;
print new Unit_Test($modules, $filter);
} catch (ORM_Validation_Exception $e) {
//.........这里部分代码省略.........
示例11: install
function install($module_name, $redirect = true)
{
$to_install = array();
if ($module_name == "*") {
foreach (module::available() as $module_name => $info) {
if (empty($info->installed)) {
$to_install[] = $module_name;
}
}
} else {
$to_install[] = $module_name;
}
foreach ($to_install as $module_name) {
if ($module_name != "gallery") {
require_once DOCROOT . "modules/{$module_name}/helpers/{$module_name}_installer.php";
}
module::install($module_name);
}
if ($redirect) {
url::redirect("scaffold");
}
}
示例12: upgrade
/**
* Upgrade a module. This will call <module>_installer::upgrade(), which is responsible for
* modifying database tables, changing module variables and calling module::set_version().
* Note that after upgrading, the module must be activated before it is available for use.
* @param string $module_name
*/
static function upgrade($module_name)
{
$kohana_modules = Kohana::config("core.modules");
array_unshift($kohana_modules, MODPATH . $module_name);
Kohana::config_set("core.modules", $kohana_modules);
$version_before = module::get_version($module_name);
$installer_class = "{$module_name}_installer";
if (method_exists($installer_class, "upgrade")) {
call_user_func_array(array($installer_class, "upgrade"), array($version_before));
} else {
$available = module::available();
if (isset($available->{$module_name}->code_version)) {
module::set_version($module_name, $available->{$module_name}->code_version);
} else {
throw new Exception("@todo UNKNOWN_MODULE");
}
}
module::load_modules();
// Now the module is upgraded but inactive, so don't leave it in the active path
array_shift($kohana_modules);
Kohana::config_set("core.modules", $kohana_modules);
$version_after = module::get_version($module_name);
if ($version_before != $version_after) {
log::success("module", t("Upgraded module %module_name from %version_before to %version_after", array("module_name" => $module_name, "version_before" => $version_before, "version_after" => $version_after)));
}
}
示例13: upgrade
/**
* Upgrade a module. This will call <module>_installer::upgrade(), which is responsible for
* modifying database tables, changing module variables and calling module::set_version().
* Note that after upgrading, the module must be activated before it is available for use.
* @param string $module_name
*/
static function upgrade($module_name)
{
$version_before = module::get_version($module_name);
$installer_class = "{$module_name}_installer";
if (method_exists($installer_class, "upgrade")) {
call_user_func_array(array($installer_class, "upgrade"), array($version_before));
} else {
$available = module::available();
if (isset($available->{$module_name}->code_version)) {
module::set_version($module_name, $available->{$module_name}->code_version);
} else {
throw new Exception("@todo UNKNOWN_MODULE");
}
}
// Now the module is upgraded so deactivate it, but we can'it deactivae gallery or the
// current identity provider.
$identity_provider = module::get_var("gallery", "identity_provider", "user");
if (!in_array($module_name, array("gallery", $identity_provider))) {
self::deactivate($module_name);
}
module::load_modules();
$version_after = module::get_version($module_name);
if ($version_before != $version_after) {
log::success("module", t("Upgraded module %module_name from %version_before to %version_after", array("module_name" => $module_name, "version_before" => $version_before, "version_after" => $version_after)));
}
}
示例14: index
public function index()
{
//Start execution timer
$bgtime = time();
$view = new Admin_View("admin.html");
$view->page_title = t("Gallery 3 :: Manage Module Updates");
$view->content = new View("admin_moduleupdates.html");
$view->content->mu_version = module::get_version("moduleupdates");
$refreshCache = false;
$cache = unserialize(Cache::instance()->get("moduleupdates_cache"));
$cache_updates = unserialize(Cache::instance()->get("moduleupdates_cache_updates"));
//if someone pressed the button to refresh now
if (request::method() == "post") {
access::verify_csrf();
$cache = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
$cache_updates = array("date" => "", "updates" => 0);
$refreshCache = true;
} else {
if (count($cache) < 1 or $cache_updates['date'] == "") {
//if there are no items in the cache array or the update date is "" refresh the data
$cache = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
$cache_updates = array("date" => "", "updates" => 0);
$refreshCache = true;
}
}
//Check the ability to access the Gallery3 GitHub
$GitHub = null;
try {
$GitHub = fopen("http://github.com", "r");
if ($GitHub != null) {
$GitHub = '<font color=green>Online</font>';
} else {
$GitHub = '<font color=red>Offline</font>';
}
} catch (Exception $e) {
}
//Check the ability to access the Google
$Google = null;
try {
$Google = fopen("http://google.com", "r");
if ($Google != null) {
$Google = '<font color=green>Online</font>';
} else {
$Google = '<font color=red>Offline</font>';
}
} catch (Exception $e) {
}
$update_count = 0;
if ($refreshCache == true) {
// Only poll GalleryModules.com once for the ini file.
$fp = fopen($this->gm_ini, 'w');
$fp2 = fopen($this->gm_core_ini, 'w');
if (function_exists("curl_init")) {
$cp = curl_init("http://www.gallerymodules.com/gallerymodules.ini");
curl_setopt($cp, CURLOPT_FILE, $fp);
$buffer = curl_exec($cp);
curl_close($cp);
fclose($fp);
$cp = curl_init("http://www.gallerymodules.com/core.ini");
curl_setopt($cp, CURLOPT_FILE, $fp2);
$buffer = curl_exec($cp);
curl_close($cp);
fclose($fp2);
} else {
fwrite($fp, file_get_contents("http://www.gallerymodules.com/gallerymodules.ini"));
fclose($fp);
fwrite($fp2, file_get_contents("http://www.gallerymodules.com/core.ini"));
fclose($fp2);
}
foreach (module::available() as $this_module_name => $module_info) {
$font_color_local = "black";
$core_version = '';
$core_server = '';
$core_dlink = '';
$font_color_core = "black";
$contrib_version = '';
$contrib_server = '';
$contrib_dlink = '';
$font_color_contrib = "black";
$gh_version = '';
$gh_server = '';
$gh_dlink = '';
$font_color_gh = "black";
$font_color_local = $this->get_local_module_version_color($module_info->version, $module_info->code_version);
list($core_version, $core_server) = $this->get_remote_module_version($this_module_name, "CORE");
$font_color_core = $this->get_module_version_color($module_info->version, $module_info->code_version, $core_version);
if (!is_numeric($core_version)) {
list($gh_version, $gh_server) = $this->get_remote_module_version($this_module_name, "GH");
$font_color_gh = $this->get_module_version_color($module_info->version, $module_info->code_version, $gh_version);
}
if ($font_color_core == "red" or $font_color_contrib == "red" or $font_color_gh == "red") {
$update_count++;
}
$module_info->name = "<a href=\"http://codex.gallery2.org/Gallery3:Modules:" . $this_module_name . "\" target=\"_new\">" . $module_info->name . "</a>";
if (is_numeric($core_version)) {
if ($core_version > $module_info->version) {
$core_dlink = "http://github.com/gallery/gallery3/tree/master/modules/" . $this_module_name;
}
}
if (is_numeric($gh_version)) {
//.........这里部分代码省略.........
示例15: index
public function index()
{
$this->template->content = View::factory('modules/index', array('modules' => module::available()));
}