From d04b88308d0b2a8fda43c4c7104c65d6cc02133f Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Fri, 7 Mar 2014 14:43:35 +0000 Subject: [PATCH] Use Extension::getType(), getName() and getPath() so we can make properties private. --- commands/core/drupal/environment.inc | 38 +++++++++++++++++++-- commands/core/drupal/environment_6.inc | 36 ++++++++++++++++++++ commands/core/drupal/environment_7.inc | 36 ++++++++++++++++++++ commands/core/drupal/pm.inc | 25 ++++++++++++++ commands/core/drupal/pm_8.inc | 29 +++++++++++++--- commands/pm/info.pm.inc | 31 +++-------------- commands/pm/pm.drush.inc | 46 +++++++++++++++----------- commands/pm/updatestatus.pm.inc | 2 +- includes/environment.inc | 4 +-- 9 files changed, 191 insertions(+), 56 deletions(-) diff --git a/commands/core/drupal/environment.inc b/commands/core/drupal/environment.inc index af34e15e12..c6cda8cf4f 100644 --- a/commands/core/drupal/environment.inc +++ b/commands/core/drupal/environment.inc @@ -19,7 +19,6 @@ function drush_get_modules($include_hidden = TRUE) { $modules = system_rebuild_module_data(); foreach ($modules as $key => $module) { - $module->type = 'module'; if ((!$include_hidden) && (isset($module->info['hidden']))) { unset($modules[$key]); } @@ -182,7 +181,6 @@ function drush_module_uninstall($modules) { function drush_get_themes($include_hidden = TRUE) { $themes = system_rebuild_theme_data(); foreach ($themes as $key => $theme) { - $theme->type = 'theme'; if (!$include_hidden) { if (isset($theme->info['hidden'])) { unset($themes[$key]); @@ -282,3 +280,39 @@ function _drush_file_private_path() { return \Drupal::config('system.file')->get('path.private'); } +/** + * Gets the extension name. + * + * @param $info + * The extension info. + * @return string + * The extension name. + */ +function _drush_pm_extension_get_name($info) { + return $info->getName(); +} + +/** + * Gets the extension type. + * + * @param $info + * The extension info. + * @return string + * The extension type. + */ +function _drush_pm_extension_get_type($info) { + return $info->getType(); +} + +/** + * Gets the extension path. + * + * @param $info + * The extension info. + * @return string + * The extension path. + */ +function _drush_pm_extension_get_path($info) { + return $info->getPath(); +} + diff --git a/commands/core/drupal/environment_6.inc b/commands/core/drupal/environment_6.inc index 1087d48706..2a20575539 100644 --- a/commands/core/drupal/environment_6.inc +++ b/commands/core/drupal/environment_6.inc @@ -317,3 +317,39 @@ function _drush_file_public_path() { function _drush_file_private_path() { // @todo } + +/** + * Gets the extension name. + * + * @param $info + * The extension info. + * @return string + * The extension name. + */ +function _drush_pm_extension_get_name($info) { + return $info->name; +} + +/** + * Gets the extension type. + * + * @param $info + * The extension info. + * @return string + * The extension type. + */ +function _drush_pm_extension_get_type($info) { + return $info->type; +} + +/** + * Gets the extension path. + * + * @param $info + * The extension info. + * @return string + * The extension path. + */ +function _drush_pm_extension_get_path($info) { + return dirname($info->filename); +} diff --git a/commands/core/drupal/environment_7.inc b/commands/core/drupal/environment_7.inc index 7258acbd22..4c015f8a64 100644 --- a/commands/core/drupal/environment_7.inc +++ b/commands/core/drupal/environment_7.inc @@ -293,3 +293,39 @@ function _drush_file_public_path() { function _drush_file_private_path() { return variable_get('file_private_path', FALSE); } + +/** + * Gets the extension name. + * + * @param $info + * The extension info. + * @return string + * The extension name. + */ +function _drush_pm_extension_get_name($info) { + return $info->name; +} + +/** + * Gets the extension type. + * + * @param $info + * The extension info. + * @return string + * The extension type. + */ +function _drush_pm_extension_get_type($info) { + return $info->type; +} + +/** + * Gets the extension path. + * + * @param $info + * The extension info. + * @return string + * The extension path. + */ +function _drush_pm_extension_get_path($info) { + return dirname($info->filename); +} diff --git a/commands/core/drupal/pm.inc b/commands/core/drupal/pm.inc index a1d3c871a8..718b6432a2 100644 --- a/commands/core/drupal/pm.inc +++ b/commands/core/drupal/pm.inc @@ -159,3 +159,28 @@ function _drush_pm_uninstall($modules) { } } +/** + * Return an array with general info of an extension. + */ +function _drush_pm_info_extension($info) { + $major_version = drush_drupal_major_version(); + + $data['extension'] = $info->name; + $data['project'] = isset($info->info['project'])?$info->info['project']:dt('Unknown'); + $data['type'] = $info->type; + $data['title'] = $info->info['name']; + $data['config'] = isset($info->info['configure']) ? $info->info['configure'] : dt('None'); + $data['description'] = $info->info['description']; + $data['version'] = $info->info['version']; + $data['date'] = $info->info['datestamp'] ? format_date($info->info['datestamp'] ?: 0, 'custom', 'Y-m-d') : NULL; + $data['package'] = $info->info['package']; + $data['core'] = $info->info['core']; + $data['php'] = $info->info['php']; + $data['status'] = drush_get_extension_status($info); + $path = (($info->type == 'module')&&($major_version == 7))?$info->uri:$info->filename; + $path = substr($path, 0, strrpos($path, '/')); + $data['path'] = $path; + + return $data; +} + diff --git a/commands/core/drupal/pm_8.inc b/commands/core/drupal/pm_8.inc index 53204c18f3..c2e2d3f13c 100644 --- a/commands/core/drupal/pm_8.inc +++ b/commands/core/drupal/pm_8.inc @@ -36,7 +36,7 @@ function _drush_pm_uninstall($args) { // Discard extensions that are not installed. foreach ($extensions as $name) { - if (!$extension_info[$name]->status && $extension_info[$name]->type == 'theme') { + if (!$extension_info[$name]->status && $extension_info[$name]->getType() == 'theme') { unset($themes[$name]); drush_log(dt('!extension is not installed.', array('!extension' => $name)), 'ok'); } @@ -97,15 +97,36 @@ function _drush_pm_uninstall($args) { // Inform the user of final status. $result_extensions = drush_get_named_extensions_list($extensions); $problem_extensions = array(); - foreach ($result_extensions as $name => $extension) { + foreach ($result_extensions as $extension) { if (!$extension->status) { - drush_log(dt('!extension was uninstalled successfully.', array('!extension' => $extension->name)), 'ok'); + drush_log(dt('!extension was uninstalled successfully.', array('!extension' => $extension->getName())), 'ok'); } else { - $problem_extensions[] = $extension->name; + $problem_extensions[] = $extension->getName(); } } if (!empty($problem_extensions)) { return drush_set_error('DRUSH_PM_UNINSTALL_EXTENSION_ISSUE', dt('There was a problem uninstalling !extension.', array('!extension' => implode(',', $problem_extensions)))); } } + +/** + * Return an array with general info of an extension. + */ +function _drush_pm_info_extension($info) { + $data['extension'] = $info->getName(); + $data['project'] = isset($info->info['project'])?$info->info['project']:dt('Unknown'); + $data['type'] = $info->getType(); + $data['title'] = $info->info['name']; + $data['config'] = isset($info->info['configure']) ? $info->info['configure'] : dt('None'); + $data['description'] = $info->info['description']; + $data['version'] = $info->info['version']; + $data['date'] = $info->info['datestamp'] ? format_date($info->info['datestamp'] ?: 0, 'custom', 'Y-m-d') : NULL; + $data['package'] = $info->info['package']; + $data['core'] = $info->info['core']; + $data['php'] = $info->info['php']; + $data['status'] = drush_get_extension_status($info); + $data['path'] = $info->getPath(); + + return $data; +} diff --git a/commands/pm/info.pm.inc b/commands/pm/info.pm.inc index 7fe4141a43..d0657db1bd 100644 --- a/commands/pm/info.pm.inc +++ b/commands/pm/info.pm.inc @@ -14,6 +14,8 @@ function drush_pm_info() { $args = array_keys($extension_info); } + drush_include_engine('drupal', 'pm', drush_drupal_major_version()); + foreach ($args as $extension) { if (isset($extension_info[$extension])) { $info = $extension_info[$extension]; @@ -22,7 +24,7 @@ function drush_pm_info() { drush_log(dt('!extension was not found.', array('!extension' => $extension)), 'warning'); continue; } - if ($info->type == 'module') { + if (_drush_pm_extension_get_type($info) == 'module') { $data = _drush_pm_info_module($info); } else { @@ -51,31 +53,6 @@ function _drush_pm_info_format_table_data($data) { return $result; } -/** - * Return an array with general info of an extension. - */ -function _drush_pm_info_extension($info) { - $major_version = drush_drupal_major_version(); - - $data['extension'] = $info->name; - $data['project'] = isset($info->info['project'])?$info->info['project']:dt('Unknown'); - $data['type'] = $info->type; - $data['title'] = $info->info['name']; - $data['config'] = isset($info->info['configure']) ? $info->info['configure'] : dt('None'); - $data['description'] = $info->info['description']; - $data['version'] = $info->info['version']; - $data['date'] = $info->info['datestamp'] ? format_date($info->info['datestamp'] ?: 0, 'custom', 'Y-m-d') : NULL; - $data['package'] = $info->info['package']; - $data['core'] = $info->info['core']; - $data['php'] = $info->info['php']; - $data['status'] = drush_get_extension_status($info); - $path = (($info->type == 'module')&&($major_version == 7))?$info->uri:$info->filename; - $path = substr($path, 0, strrpos($path, '/')); - $data['path'] = $path; - - return $data; -} - /** * Return an array with info of a module. */ @@ -107,7 +84,7 @@ function _drush_pm_info_module($info) { $data['required_by'] = $requiredby; if ($info->status == 1) { $role = drush_role_get_class(); - $data['permissions'] = $role->getModulePerms($info->name); + $data['permissions'] = $role->getModulePerms(_drush_pm_extension_get_name($info)); } return $data; } diff --git a/commands/pm/pm.drush.inc b/commands/pm/pm.drush.inc index 8823743f07..58c373e3d5 100644 --- a/commands/pm/pm.drush.inc +++ b/commands/pm/pm.drush.inc @@ -446,10 +446,12 @@ function pm_complete_projects() { * It will sort first by type, second by package and third by name. */ function _drush_pm_sort_extensions($a, $b) { - if ($a->type == 'module' && $b->type == 'theme') { + $a_type = _drush_pm_extension_get_type($a); + $b_type = _drush_pm_extension_get_type($b); + if ($a_type == 'module' && $b_type == 'theme') { return -1; } - if ($a->type == 'theme' && $b->type == 'module') { + if ($a_type == 'theme' && $b_type == 'module') { return 1; } $cmp = strcasecmp($a->info['package'], $b->info['package']); @@ -469,7 +471,7 @@ function _drush_pm_sort_extensions($a, $b) { * String describing extension status. Values: enabled|disabled|not installed */ function drush_get_extension_status($extension) { - if (($extension->type == 'module')&&($extension->schema_version == -1)) { + if ((_drush_pm_extension_get_type($extension) == 'module') && ($extension->schema_version == -1)) { $status = "not installed"; } else { @@ -495,10 +497,11 @@ function drush_pm_classify_extensions(&$extensions, &$modules, &$themes, $extens if (!isset($extension_info[$extension])) { continue; } - if ($extension_info[$extension]->type == 'module') { + $type = _drush_pm_extension_get_type($extension_info[$extension]); + if ($type == 'module') { $modules[$extension] = $extension; } - else if ($extension_info[$extension]->type == 'theme') { + else if ($type == 'theme') { $themes[$extension] = $extension; } } @@ -544,13 +547,15 @@ function drush_get_projects(&$extensions = NULL) { $project = 'drupal'; } else { - if (is_dir(dirname($extension->filename) . '/CVS') && (!module_exists('cvs_deploy'))) { + $extension_name = _drush_pm_extension_get_name($extension); + $extension_path = _drush_pm_extension_get_path($extension); + if (is_dir($extension_path . '/CVS') && (!module_exists('cvs_deploy'))) { $extension->vcs = 'cvs'; - drush_log(dt('Extension !extension is fetched from cvs. Ignoring.', array('!extension' => $extension->name)), 'debug'); + drush_log(dt('Extension !extension is fetched from cvs. Ignoring.', array('!extension' => $extension_name)), 'debug'); } - elseif (is_dir(dirname($extension->filename) . '/.git') && (!module_exists('git_deploy'))) { + elseif (is_dir($extension_path . '/.git') && (!module_exists('git_deploy'))) { $extension->vcs = 'git'; - drush_log(dt('Extension !extension is fetched from git. Ignoring.', array('!extension' => $extension->name)), 'debug'); + drush_log(dt('Extension !extension is fetched from git. Ignoring.', array('!extension' => $extension_name)), 'debug'); } continue; } @@ -567,7 +572,7 @@ function drush_get_projects(&$extensions = NULL) { // no direct relation with the project name. For example, // "Text (text)" or "Number (number)" for the CCK project. 'label' => isset($extensions[$project])?$extensions[$project]->label:$project, - 'type' => $extension->type, + 'type' => _drush_pm_extension_get_type($extension), 'version' => $extension->info['version'], 'status' => $extension->status, 'extensions' => array(), @@ -579,7 +584,7 @@ function drush_get_projects(&$extensions = NULL) { elseif ($extension->status != 0) { $projects[$project]['status'] = $extension->status; } - $projects[$project]['extensions'][] = $extension->name; + $projects[$project]['extensions'][] = _drush_pm_extension_get_name($extension); } // Obtain each project's path and try to provide a better label for ones @@ -758,7 +763,7 @@ function drush_pm_list() { $major_version = drush_drupal_major_version(); foreach ($extension_info as $key => $extension) { - if (!in_array($extension->type, $type_filter)) { + if (!in_array(_drush_pm_extension_get_type($extension), $type_filter)) { unset($extension_info[$key]); continue; } @@ -794,12 +799,12 @@ function drush_pm_list() { $row['package'] = $extension->info['package']; $row['name'] = $extension->label; - $row['type'] = ucfirst($extension->type); + $row['type'] = ucfirst(_drush_pm_extension_get_type($extension)); $row['status'] = ucfirst($status); // Suppress notice when version is not present. $row['version'] = @$extension->info['version']; - $result[$extension->name] = $row; + $result[$key] = $row; unset($row); } // In Drush-5, we used to return $extension_info here. @@ -829,6 +834,7 @@ function drush_pm_find_project_from_extension($extension) { * Validate callback. Determine the modules and themes that the user would like enabled. */ function drush_pm_enable_validate() { + drush_include_engine('drupal', 'pm', drush_drupal_major_version()); $args = pm_parse_arguments(func_get_args()); $extension_info = drush_get_extensions(); @@ -875,7 +881,7 @@ function drush_pm_enable_validate() { // Check if the extension is compatible with Drupal core and php version. if ($component = drush_extension_check_incompatibility($extension_info[$name])) { drush_set_error('DRUSH_PM_ENABLE_MODULE_INCOMPATIBLE', dt('!name is incompatible with the !component version.', array('!name' => $name, '!component' => $component))); - if ($extension_info[$name]->type == 'module') { + if (_drush_pm_extension_get_type($extension_info[$name]) == 'module') { unset($modules[$name]); } else { @@ -963,7 +969,7 @@ function drush_pm_enable_validate() { $searchpath = array(); foreach (array_merge($modules, $themes) as $name) { - $searchpath[] = dirname($extension_info[$name]->filename); + $searchpath[] = _drush_pm_extension_get_path($extension_info[$name]); } // Add all modules that passed validation to the drush // list of commandfiles (if they have any). This @@ -1019,14 +1025,14 @@ function drush_pm_enable() { $role = drush_role_get_class(); foreach ($result_extensions as $name => $extension) { if ($extension->status) { - drush_log(dt('!extension was enabled successfully.', array('!extension' => $extension->name)), 'ok'); - $perms = $role->getModulePerms($extension->name); + drush_log(dt('!extension was enabled successfully.', array('!extension' => $name)), 'ok'); + $perms = $role->getModulePerms($name); if (!empty($perms)) { - drush_print(dt('!extension defines the following permissions: !perms', array('!extension' => $extension->name, '!perms' => implode(', ', $perms)))); + drush_print(dt('!extension defines the following permissions: !perms', array('!extension' => $name, '!perms' => implode(', ', $perms)))); } } else { - $problem_extensions[] = $extension->name; + $problem_extensions[] = $name; } } if (!empty($problem_extensions)) { diff --git a/commands/pm/updatestatus.pm.inc b/commands/pm/updatestatus.pm.inc index b9f37968fb..fbf97a8e8b 100644 --- a/commands/pm/updatestatus.pm.inc +++ b/commands/pm/updatestatus.pm.inc @@ -48,7 +48,7 @@ function drush_pm_updatestatus() { } // Additionally if the extension name is distinct to the project name and // the user asked to update the extension, fix the request. - elseif ((isset($requests[$name])) && ($extension->name != $extension->info['project'])) { + elseif ((isset($requests[$name])) && ($name != $extension->info['project'])) { $requests[$extension->info['project']] = $requests[$name]; unset($requests[$name]); } diff --git a/includes/environment.inc b/includes/environment.inc index 656cd16be9..5e13038977 100644 --- a/includes/environment.inc +++ b/includes/environment.inc @@ -807,11 +807,11 @@ function drush_get_extensions($include_hidden = TRUE) { $extensions = array_merge(drush_get_modules($include_hidden), drush_get_themes($include_hidden)); foreach ($extensions as $name => $extension) { if (isset($extension->info['name'])) { - $extensions[$name]->label = $extension->info['name'].' ('.$extension->name.')'; + $extensions[$name]->label = $extension->info['name'].' ('.$name.')'; } else { drush_log(dt("Extension !name provides no human-readable name in .info file.", array('!name' => $name), 'debug')); - $extensions[$name]->label = $name.' ('.$extension->name.')'; + $extensions[$name]->label = $name.' ('.$name.')'; } if (empty($extension->info['package'])) { $extensions[$name]->info['package'] = dt('Other');