Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
project_composer
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
project_composer
Commits
1070e120
Commit
1070e120
authored
9 months ago
by
Neil Drumm
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3381080
: Add drush command to delete a project’s metadata
parent
0d88f69d
No related branches found
No related tags found
No related merge requests found
Pipeline
#239850
passed with warnings
9 months ago
Stage: build
Stage: validate
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
project_composer.changes.inc
+2
-2
2 additions, 2 deletions
project_composer.changes.inc
project_composer.drush.inc
+98
-0
98 additions, 0 deletions
project_composer.drush.inc
project_composer.module
+1
-0
1 addition, 0 deletions
project_composer.module
with
101 additions
and
2 deletions
project_composer.changes.inc
+
2
−
2
View file @
1070e120
...
...
@@ -42,13 +42,13 @@ function project_composer_changes($release_category) {
// Generate output.
$actions
=
[];
$result
=
db_query
(
'SELECT package, updated FROM {project_composer_update_log} WHERE category = :release_category AND updated > :since'
,
[
$result
=
db_query
(
'SELECT package, updated
, deleted
FROM {project_composer_update_log} WHERE category = :release_category AND updated > :since'
,
[
':release_category'
=>
$release_category
,
':since'
=>
floor
(
$since
/
10000
),
]);
foreach
(
$result
as
$row
)
{
$actions
[]
=
[
'type'
=>
'update'
,
'type'
=>
$row
->
deleted
?
'delete'
:
'update'
,
'package'
=>
'drupal/'
.
$row
->
package
,
'time'
=>
$row
->
updated
];
...
...
This diff is collapsed.
Click to expand it.
project_composer.drush.inc
+
98
−
0
View file @
1070e120
...
...
@@ -45,6 +45,13 @@ function project_composer_drush_command() {
'callback'
=>
'drush_project_composer_validate_constraints'
,
'aliases'
=>
array
(
'pcvc'
),
);
$items
[
'project-composer-delete-project-metadata'
]
=
[
'description'
=>
'Delete metadata for a project.'
,
'arguments'
=>
[
'project'
=>
'Project machine name'
,
],
];
return
$items
;
}
...
...
@@ -222,3 +229,94 @@ function drush_project_composer_validate_constraints() {
}
}
}
/**
* Delete metadata for a project.
*/
function
drush_project_composer_delete_project_metadata
(
$shortname
)
{
if
(
!
(
$project_node
=
project_load
(
$shortname
)))
{
drush_log
(
dt
(
'Could not load project'
),
'error'
);
}
// Get namespace map data.
$result
=
db_query
(
'SELECT map_id, component_name, package_namespace, category FROM {project_composer_namespace_map} WHERE project_nid = :project_nid'
,
[
':project_nid'
=>
$project_node
->
nid
,
])
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
$map_ids
=
array_column
(
$result
,
'map_id'
);
if
(
!
empty
(
$map_ids
))
{
array_unshift
(
$result
,
array_keys
(
$result
[
0
]));
drush_print
(
drush_format_table
(
$result
));
}
// Get component data.
if
(
$release_nids
=
_project_composer_get_release_nids
(
$project_node
->
nid
))
{
$result
=
db_query
(
'SELECT component_id, component_role, name, package, release_nid, title FROM {project_composer_component} WHERE release_nid IN (:release_nids)'
,
[
':release_nids'
=>
$release_nids
,
])
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
$component_ids
=
array_column
(
$result
,
'component_id'
);
if
(
!
empty
(
$component_ids
))
{
array_unshift
(
$result
,
array_keys
(
$result
[
0
]));
drush_print
(
drush_format_table
(
$result
));
}
}
// Get files to delete.
$filepaths
=
[];
foreach
([
'legacy'
,
'current'
]
as
$release_category
)
{
if
(
$namespace
=
project_composer_get_project_namespace
(
$project_node
->
nid
,
$release_category
,
FALSE
))
{
foreach
([
PROJECT_COMPOSER_METADATA_TAGGED
,
PROJECT_COMPOSER_METADATA_DEV
]
as
$build_type
)
{
$filepath
=
_project_composer_get_metadata_file_dir
(
$release_category
)
.
'/'
.
project_composer_get_filename
(
$namespace
,
$build_type
);
if
(
file_exists
(
$filepath
))
{
$filepaths
[
$release_category
.
'-'
.
$build_type
]
=
$filepath
;
}
}
}
}
if
(
empty
(
$filepaths
))
{
drush_print
(
dt
(
'Nothing to delete.'
));
return
;
}
// Confirm.
drush_print
(
dt
(
'You are about to delete:'
));
foreach
(
$filepaths
as
$filepath
)
{
drush_print
(
dt
(
'- @filepath'
,
[
'@filepath'
=>
$filepath
]));
}
if
(
!
drush_confirm
(
dt
(
'Do you want to continue?'
)))
{
return
;
}
// Delete from namespace map & components.
if
(
!
empty
(
$map_ids
))
{
db_delete
(
'project_composer_namespace_map'
)
->
condition
(
'map_id'
,
$map_ids
)
->
execute
();
}
if
(
!
empty
(
$component_ids
))
{
db_delete
(
'project_composer_component'
)
->
condition
(
'component_id'
,
$component_ids
)
->
execute
();
}
// Delete files.
foreach
(
$filepaths
as
$category_type
=>
$filepath
)
{
file_unmanaged_delete
(
$filepath
);
// Clear CDN cache.
$url
=
url
(
preg_replace
(
'|public:/|'
,
'files'
,
$filepath
),
[
'absolute'
=>
TRUE
]);
drupalorg_crosssite_fastly_purge_url
(
$url
);
// Update project_composer_update_log table.
list
(
$release_category
,
$build_type
)
=
explode
(
'-'
,
$category_type
);
db_merge
(
'project_composer_update_log'
)
->
key
([
'category'
=>
$release_category
,
'package'
=>
$namespace
.
(
$build_type
===
PROJECT_COMPOSER_METADATA_DEV
?
'~dev'
:
''
),
])
->
fields
([
'updated'
=>
time
(),
'deleted'
=>
1
,
])
->
execute
();
}
}
This diff is collapsed.
Click to expand it.
project_composer.module
+
1
−
0
View file @
1070e120
...
...
@@ -1910,6 +1910,7 @@ function project_composer_write_json($release_category, $json, $packagename = NU
])
->
fields
([
'updated'
=>
filemtime
(
$filepath
),
'deleted'
=>
0
,
])
->
execute
();
}
...
...
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