Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
node_revision_delete
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
node_revision_delete
Commits
4b92072c
Commit
4b92072c
authored
3 years ago
by
Guido Robertone
Committed by
Adrian Cid Almaguer
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2911851
: Drush command to configure the tracked content types
parent
0b5cca98
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!5
Issue #2911851: Drush command to configure the tracked content types
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Commands/NodeRevisionDeleteCommands.php
+65
-0
65 additions, 0 deletions
src/Commands/NodeRevisionDeleteCommands.php
with
65 additions
and
0 deletions
src/Commands/NodeRevisionDeleteCommands.php
+
65
−
0
View file @
4b92072c
...
...
@@ -3,6 +3,7 @@
namespace
Drupal\node_revision_delete\Commands
;
use
Drupal\Core\Config\ConfigFactoryInterface
;
use
Drupal\node\Entity\NodeType
;
use
Drupal\node_revision_delete
\NodeRevisionDeleteInterface
;
use
Drush\Commands\DrushCommands
;
use
Consolidation\AnnotatedCommand\CommandData
;
...
...
@@ -514,4 +515,68 @@ class NodeRevisionDeleteCommands extends DrushCommands {
return
TRUE
;
}
/**
* Track a content type into node revision delete system.
*
* @usage nrd-track article 50 1 15
* Track the article content type with:
* 50 minimum number of revision to keep.
* 1 minimum age of revision to delete.
* 15 when to delete the revisions.
*
* @command nrd:track
* @aliases nrd-t, nrd-track
*/
public
function
track
(
string
$content_type
,
int
$minimum_revisions_to_keep
,
int
$minimum_age_to_delete
,
int
$when_to_delete
)
{
// Content_type argument must be string.
if
(
!
is_string
(
$content_type
))
{
$this
->
io
()
->
error
(
dt
(
'Argument content type must be string.'
));
return
FALSE
;
}
// Validate for a valid content type.
$content_types
=
$this
->
entityTypeManager
->
getStorage
(
'node_type'
)
->
loadMultiple
();
$content_types_ids
=
array_map
(
function
(
NodeType
$object
)
{
return
$object
->
id
();
},
$content_types
);
if
(
!
in_array
(
$content_type
,
$content_types_ids
))
{
$this
->
io
()
->
error
(
dt
(
'Argument content type is not a valid content type.'
));
return
FALSE
;
}
// minimum_revisions_to_keep argument must be numeric.
if
(
!
is_int
(
$minimum_revisions_to_keep
))
{
$this
->
io
()
->
error
(
dt
(
'Argument minimum_revisions_to_keep must be numeric.'
));
return
FALSE
;
}
// minimum_age_to_delete argument must be numeric.
if
(
!
is_int
(
$minimum_age_to_delete
))
{
$this
->
io
()
->
error
(
dt
(
'Argument minimum_age_to_delete must be numeric.'
));
return
FALSE
;
}
// when_to_delete argument must be numeric.
if
(
!
is_int
(
$when_to_delete
))
{
$this
->
io
()
->
error
(
dt
(
'Argument when_to_delete must be numeric.'
));
return
FALSE
;
}
// Validate for Maximum number allowed.
$config
=
$this
->
configFactory
->
getEditable
(
'node_revision_delete.settings'
);
$node_revision_delete_minimum_age_to_delete_time
=
$config
->
get
(
'node_revision_delete_minimum_age_to_delete_time'
);
$node_revision_delete_when_to_delete_time
=
$config
->
get
(
'node_revision_delete_when_to_delete_time'
);
if
(
$minimum_age_to_delete
>
$node_revision_delete_minimum_age_to_delete_time
[
'max_number'
])
{
$this
->
io
()
->
error
(
dt
(
'Argument minimum_age_to_delete must lower than Maximum Age of revision to delete.'
));
return
FALSE
;
}
if
(
$when_to_delete
>
$node_revision_delete_when_to_delete_time
[
'max_number'
])
{
$this
->
io
()
->
error
(
dt
(
'Argument when_to_delete must lower than Maximum of When to Delete.'
));
return
FALSE
;
}
$this
->
nodeRevisionDelete
->
saveContentTypeConfig
(
$content_type
,
$minimum_revisions_to_keep
,
$minimum_age_to_delete
,
$when_to_delete
);
return
TRUE
;
}
}
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