Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
unused_modules
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
unused_modules
Merge requests
!9
Issue
#3445619
- Remove file
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3445619
- Remove file
issue/unused_modules-3445619:3445619-remove-old-drush
into
8.x-1.x
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Viktor Holovachek
requested to merge
issue/unused_modules-3445619:3445619-remove-old-drush
into
8.x-1.x
11 months ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
Closes
#3445619
0
0
Merge request reports
Compare
8.x-1.x
8.x-1.x (base)
and
latest version
latest version
9cb0d558
1 commit,
11 months ago
1 file
+
0
−
198
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
unused_modules.drush.inc deleted
100644 → 0
+
0
−
198
Options
<?php
/**
* @file
* Unused Modules Drush support.
*/
/**
* Implements hook_drush_command().
*/
function
unused_modules_drush_command
()
{
$items
=
[];
$items
[
'unused-modules'
]
=
[
'description'
=>
'Show unused modules or projects.'
,
'aliases'
=>
[
'um'
,
'unused_modules'
],
'arguments'
=>
[
'type'
=>
'Options "projects" and "modules". Show modules or projects (defaults to projects).'
,
'show'
=>
'Options "all" and "disabled". Show only disabled modules (defaults to disabled).'
,
],
'examples'
=>
[
'Show projects that are unused.'
=>
'drush unused-modules projects disabled'
,
'As above, shorthand.'
=>
'drush um'
,
'As above, include projects with enabled modules.'
=>
'drush unused-modules projects disabled'
,
'Show modules that are unused.'
=>
'drush unused-modules modules disabled'
,
'As above, include enabled modules.'
=>
'drush unused-modules modules all'
,
],
];
return
$items
;
}
/**
* Implements hook_drush_help().
*/
function
unused_modules_drush_help
(
$section
)
{
switch
(
$section
)
{
case
'drush:unused-modules'
:
return
dt
(
"Show modules and projects that are unused."
);
}
}
/**
* Drush command callback.
*/
function
drush_unused_modules
(
$type
=
"projects"
,
$show
=
"disabled"
)
{
// Print projects.
if
(
$type
==
'projects'
)
{
if
(
$show
==
'all'
)
{
drush_unused_modules_show_projects
(
'all'
);
}
elseif
(
$show
==
'disabled'
)
{
drush_unused_modules_show_projects
(
'disabled'
);
}
else
{
drush_set_error
(
"unknown 'show' argument "
.
$show
.
". See drush unused-modules --help"
);
}
}
// Print modules.
elseif
(
$type
==
'modules'
)
{
if
(
$show
==
'all'
)
{
drush_unused_modules_show_modules
(
'all'
);
}
elseif
(
$show
==
'disabled'
)
{
drush_unused_modules_show_modules
(
'disabled'
);
}
else
{
drush_set_error
(
"unknown 'show' argument "
.
$show
.
". See drush unused-modules --help"
);
}
}
else
{
drush_set_error
(
"unknown 'type' argument "
.
$type
.
". See drush unused-modules --help"
);
}
}
/**
* Drush callback.
*
* Prints a table with orphaned projects.
*
* @param string $op
* Either 'all' or 'disabled'.
*
* @return string
* themed table.
*/
function
drush_unused_modules_show_projects
(
$op
=
'all'
)
{
/** @var \Drupal\unused_modules\UnusedModulesHelperService $helper */
$helper
=
\Drupal
::
service
(
'unused_modules.helper'
);
$modules
=
$helper
->
getModulesByProject
();
$header
=
[
'Project'
,
'Project has Enabled Modules'
,
'Project Path'
,
];
// With Drush, the first row is the header.
$rows
=
[];
$rows
[]
=
$header
;
foreach
(
$modules
as
$module
)
{
if
(
$op
==
'all'
)
{
$rows
[
$module
->
projectName
]
=
[
$module
->
projectName
,
$module
->
projectHasEnabledModules
?
t
(
"Yes"
)
:
t
(
"No"
),
$module
->
projectPath
,
];
}
elseif
(
$op
==
'disabled'
)
{
if
(
!
$module
->
projectHasEnabledModules
)
{
$rows
[
$module
->
projectName
]
=
[
$module
->
projectName
,
$module
->
projectHasEnabledModules
?
t
(
"Yes"
)
:
t
(
"No"
),
$module
->
projectPath
,
];
}
}
}
// Note: header is always there.
if
(
count
(
$rows
)
===
1
)
{
drush_print
(
"Hurray, no orphaned projects!"
);
}
else
{
drush_print_table
(
$rows
,
TRUE
);
}
}
/**
* Drush callback.
*
* Prints a table with orphaned modules.
*
* @param string $op
* Either 'all' or 'disabled'.
*
* @return string
* themed table.
*/
function
drush_unused_modules_show_modules
(
$op
=
'all'
)
{
/** @var \Drupal\unused_modules\UnusedModulesHelperService $helper */
$helper
=
\Drupal
::
service
(
'unused_modules.helper'
);
$modules
=
$helper
->
getModulesByProject
();
$header
=
[
'Project'
,
'Module'
,
'Module enabled'
,
'Project has Enabled Modules'
,
'Project Path'
,
];
// With Drush, the first row is the header.
$rows
=
[];
$rows
[]
=
$header
;
foreach
(
$modules
as
$module
)
{
if
(
$op
==
'all'
)
{
$rows
[
$module
->
getName
()]
=
[
$module
->
projectName
,
$module
->
getName
(),
$module
->
moduleIsEnabled
?
t
(
"Yes"
)
:
t
(
"No"
),
$module
->
projectHasEnabledModules
?
t
(
"Yes"
)
:
t
(
"No"
),
$module
->
projectPath
,
];
}
elseif
(
$op
==
'disabled'
)
{
if
(
!
$module
->
projectHasEnabledModules
)
{
$rows
[
$module
->
getName
()]
=
[
$module
->
projectName
,
$module
->
getName
(),
$module
->
moduleIsEnabled
?
t
(
"Yes"
)
:
t
(
"No"
),
$module
->
projectHasEnabledModules
?
t
(
"Yes"
)
:
t
(
"No"
),
$module
->
projectPath
,
];
}
}
}
// Note: header is always there.
if
(
count
(
$rows
)
===
1
)
{
drush_print
(
"Hurray, no orphaned modules!"
);
}
else
{
drush_print_table
(
$rows
,
TRUE
);
}
}
/**
* Implements hook_drush_command_alter().
*/
function
unused_modules_drush_command_alter
(
&
$command
)
{
if
(
$command
[
'command'
]
==
'audit_extensions'
)
{
$command
[
'checks'
][]
=
[
'name'
=>
'Unused'
,
'location'
=>
__DIR__
.
'/unused_modules.site_audit.inc'
,
];
}
}
Loading