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
Commits
8b2604c2
Commit
8b2604c2
authored
1 year ago
by
GRM
Browse files
Options
Downloads
Patches
Plain Diff
issue 3422745: add drush export and import
parent
b5d2585e
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!3
issue 3422745: add drush export and import
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
drush.services.yml
+6
-0
6 additions, 0 deletions
drush.services.yml
src/Drush/Commands/ModuleUsageCommands.php
+85
-0
85 additions, 0 deletions
src/Drush/Commands/ModuleUsageCommands.php
with
91 additions
and
0 deletions
drush.services.yml
0 → 100644
+
6
−
0
View file @
8b2604c2
services
:
module_usage.commands
:
class
:
Drupal\module_usage\Drush\Commands\ModuleUsageCommands
arguments
:
[
'
@module_usage.usage_service'
,
'
@module_usage.query'
]
tags
:
-
{
name
:
drush.command
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Drush/Commands/ModuleUsageCommands.php
0 → 100644
+
85
−
0
View file @
8b2604c2
<?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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment