Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
views_data_export
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
views_data_export
Merge requests
!34
Issue
#2887450
: Re-add Drush commands
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#2887450
: Re-add Drush commands
issue/views_data_export-2887450:2887450-re-add-drush-commands
into
8.x-1.x
Overview
0
Commits
19
Pipelines
19
Changes
3
Open
Steffen Schlaer
requested to merge
issue/views_data_export-2887450:2887450-re-add-drush-commands
into
8.x-1.x
1 year ago
Overview
0
Commits
19
Pipelines
19
Changes
3
Expand
Closes
#2887450
0
0
Merge request reports
Compare
8.x-1.x
version 18
3cb9ea01
2 months ago
version 17
e35c2055
3 months ago
version 16
795fa6ad
3 months ago
version 15
20ad36ab
3 months ago
version 14
449f7944
4 months ago
version 13
ffb0f9eb
4 months ago
version 12
bd6cf30a
4 months ago
version 11
ab6a7768
6 months ago
version 10
66b55e70
6 months ago
version 9
c592848f
6 months ago
version 8
88273aa0
7 months ago
version 7
56a27886
7 months ago
version 6
eb2feb63
7 months ago
version 5
cbb6bd84
7 months ago
version 4
ef17e269
7 months ago
version 3
2eea0aab
7 months ago
version 2
b0e904ff
8 months ago
version 1
aabf0848
1 year ago
8.x-1.x (HEAD)
and
latest version
latest version
53257654
19 commits,
2 months ago
version 18
3cb9ea01
18 commits,
2 months ago
version 17
e35c2055
17 commits,
3 months ago
version 16
795fa6ad
16 commits,
3 months ago
version 15
20ad36ab
15 commits,
3 months ago
version 14
449f7944
14 commits,
4 months ago
version 13
ffb0f9eb
13 commits,
4 months ago
version 12
bd6cf30a
12 commits,
4 months ago
version 11
ab6a7768
11 commits,
6 months ago
version 10
66b55e70
10 commits,
6 months ago
version 9
c592848f
9 commits,
6 months ago
version 8
88273aa0
8 commits,
7 months ago
version 7
56a27886
7 commits,
7 months ago
version 6
eb2feb63
6 commits,
7 months ago
version 5
cbb6bd84
5 commits,
7 months ago
version 4
ef17e269
4 commits,
7 months ago
version 3
2eea0aab
3 commits,
7 months ago
version 2
b0e904ff
2 commits,
8 months ago
version 1
aabf0848
1 commit,
1 year ago
3 files
+
341
−
90
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
src/Drush/Commands/ViewsDataExportCommands.php
0 → 100644
+
112
−
0
Options
<?php
namespace
Drupal\views_data_export\Drush\Commands
;
use
Consolidation\AnnotatedCommand\CommandData
;
use
Consolidation\AnnotatedCommand\CommandError
;
use
Drupal\Core\Session\AccountSwitcherInterface
;
use
Drupal\Core\Session\UserSession
;
use
Drupal\views\Views
;
use
Drupal\views_data_export
\Plugin\views\display\DataExport
;
use
Drush\Attributes
as
CLI
;
use
Drush\Commands\AutowireTrait
;
use
Drush\Commands\DrushCommands
;
/**
* Provides Drush commands for exporting views.
*/
class
ViewsDataExportCommands
extends
DrushCommands
{
use
AutowireTrait
;
public
function
__construct
(
protected
AccountSwitcherInterface
$accountSwitcher
,
)
{
parent
::
__construct
();
}
/**
* Implements views_data_export command arguments validation.
*
* @hook validate views_data_export:views-data-export
*/
public
function
viewsDataExportValidate
(
CommandData
$commandData
)
{
$input
=
$commandData
->
input
();
$view_name
=
$input
->
getArgument
(
'view_name'
);
$display_id
=
$input
->
getArgument
(
'display_id'
);
$output_file
=
$input
->
getArgument
(
'output_file'
);
$options
=
$commandData
->
options
();
$force
=
$options
[
'force'
];
// Verify view existence.
$view
=
Views
::
getView
(
$view_name
);
if
(
is_null
(
$view
))
{
return
new
CommandError
(
dt
(
'The view !view does not exist.'
,
[
'!view'
=>
$view_name
]));
}
// Verify existence of the display.
if
(
$view
->
setDisplay
(
$display_id
)
===
FALSE
)
{
return
new
CommandError
(
dt
(
'The view !view does not have the !display display.'
,
[
'!view'
=>
$view_name
,
'!display'
=>
$display_id
,
]));
}
// Verify the display type.
$view_display
=
$view
->
getDisplay
();
if
(
$view_display
->
getPluginId
()
!==
'data_export'
)
{
return
new
CommandError
(
dt
(
'Incorrect display_id provided, expected a views data export display, found !display instead.'
,
[
'!display'
=>
$view_display
->
getPluginId
(),
]));
}
// Verify final file location.
if
(
!
empty
(
$output_file
))
{
if
(
!
$force
&&
file_exists
(
$output_file
))
{
return
new
CommandError
(
dt
(
'The desired output file already exists. Please remove the file and try again.'
));
}
if
(
!
is_writable
(
dirname
(
$output_file
)))
{
return
new
CommandError
(
dt
(
'The desired output location or file is unwritable. Please check your permissions or location and try again.'
));
}
}
}
/**
* Executes views_data_export display of a view and writes the output to file.
*/
#[CLI\Command(name: 'views_data_export:views-data-export', aliases: ['vde'])]
#[CLI\Argument(name: 'view_name', description: 'The name of the view.')]
#[CLI\Argument(name: 'display_id', description: 'The id of the views_data_export display to execute on the view.')]
#[CLI\Argument(name: 'output_file', description: 'he location to place the final generated file. Leave blank for default location in private files.')]
#[CLI\Argument(name: 'arguments', description: 'The views contextual filter arguments, if any.')]
#[CLI\Usage(name: 'views_data_export:views-data-export my_view_name views_data_export_display_id output_file_path', description: 'Export my_view_name:views_data_export_display_id.')]
#[CLI\Option(name: 'force', description: 'Overwrite the output file if the file exists.')]
public
function
viewsDataExport
(
string
$view_name
,
string
$display_id
,
?string
$output_file
=
NULL
,
string
$arguments
=
''
):
void
{
$this
->
logger
()
->
notice
(
dt
(
'Starting data export..'
));
$args
=
[];
if
(
$arguments
)
{
$args
=
explode
(
'/'
,
$arguments
);
}
$this
->
accountSwitcher
->
switchTo
(
new
UserSession
([
'uid'
=>
1
]));
$result
=
DataExport
::
buildResponse
(
$view_name
,
$display_id
,
$args
,
[
'vde_drush'
,
$output_file
,
]);
if
(
!
empty
(
$result
[
'drush_batch_process_finished'
])
||
!
empty
(
$result
[
'drush_process_finished'
]))
{
if
(
!
empty
(
$result
[
0
][
'vde_file'
]))
{
$this
->
logger
()
->
success
(
dt
(
'Data export saved to !output_file'
,
[
'!output_file'
=>
$result
[
0
][
'vde_file'
]]));
}
$this
->
logger
()
->
success
(
dt
(
'Data export finished.'
));
}
else
{
$this
->
logger
()
->
error
(
dt
(
'Unable to export views data. Please check site logs.'
));
}
$this
->
accountSwitcher
->
switchBack
();
}
}
Loading