Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
module_usage
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
module_usage
Merge requests
!3
issue 3422745: add drush export and import
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
issue 3422745: add drush export and import
issue/module_usage-3422745:3422745-drush-import-export
into
1.0.x
Overview
0
Commits
1
Pipelines
0
Changes
2
Merged
datawench
requested to merge
issue/module_usage-3422745:3422745-drush-import-export
into
1.0.x
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
2
Expand
Closes
#3422745
0
0
Merge request reports
Compare
1.0.x
1.0.x (base)
and
latest version
latest version
8b2604c2
1 commit,
1 year ago
2 files
+
91
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/Drush/Commands/ModuleUsageCommands.php
0 → 100644
+
85
−
0
Options
<?php
namespace
Drupal\module_usage\Drush\Commands
;
use
Drupal\Component\Serialization\Json
;
use
Drupal\Core\File\FileSystemInterface
;
use
Drupal\module_usage
\Services\ModuleUsageService
;
use
Drupal\module_usage
\Services\QueryService
;
use
Drush\Commands\DrushCommands
;
/**
* Provide drush commands.
*
* @class ModuleUsageCommands
*/
class
ModuleUsageCommands
extends
DrushCommands
{
/**
* The module usage service.
*
* @var ModuleUsageService
*/
private
ModuleUsageService
$moduleUsageService
;
/**
* @var QueryService
*/
private
QueryService
$queryService
;
/**
* The constructor.
*
* @param ModuleUsageService $moduleUsageService
* The module usage service.
*/
public
function
__construct
(
ModuleUsageService
$moduleUsageService
,
QueryService
$queryService
)
{
parent
::
__construct
();
$this
->
moduleUsageService
=
$moduleUsageService
;
$this
->
queryService
=
$queryService
;
}
/**
* @command moduse:export
* @aliases moduse-export
* @option path
*
* @param array $options
*
* @return void
*/
public
function
export
(
array
$options
=
[
'path'
=>
'private://moduse'
,
]
)
:
void
{
$data
=
$this
->
moduleUsageService
->
exportModuleUsageData
();
$directory
=
$options
[
'path'
];
if
(
\Drupal
::
service
(
'file_system'
)
->
prepareDirectory
(
$directory
,
FileSystemInterface
::
CREATE_DIRECTORY
|
FileSystemInterface
::
MODIFY_PERMISSIONS
))
{
file_put_contents
(
$directory
.
'/moduse.json'
,
$data
);
}
}
/**
* @command moduse:import
* @aliases moduse-import
* @option path
*
* @param array $options
*
* @return void
* @throws \Exception
*/
public
function
import
(
array
$options
=
[
'path'
=>
'private://moduse'
,
]
)
:
void
{
$directory
=
$options
[
'path'
];
if
(
$data
=
file_get_contents
(
$directory
.
'/moduse.json'
))
{
$data
=
Json
::
decode
(
$data
);
if
(
$data
)
{
$this
->
queryService
->
doImport
(
$data
);
}
}
}
}
\ No newline at end of file
Loading