Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

EZP-29451: As an Administrator I want to have a CLI command for database cleanup #2431

Merged
merged 13 commits into from
Dec 19, 2018

Conversation

kmadejski
Copy link
Member

@kmadejski kmadejski commented Aug 29, 2018

Question Answer
JIRA issue EZP-29451
Bug/Improvement no
New feature yes
Target version master
BC breaks no
Doc needed yes

This PR introduces the new command which allows to clean up the database from the unwanted, archived content versions as well as unwanted drafts.

Big thanks for XROW (https://github.com/xrowgmbh) who provided POC for this command!

Open questions to reviewers:

  • Since this command might be considered as a reflection of legacy's flatten script (https://github.com/ezsystems/ezpublish-legacy/blob/master/bin/php/flatten.php), the question is whether we want to make it smart enough to clean up also temporary content classes and temporary roles as the previous script could do? I think that if we want these functionalities, then it should be done as a separated command.
  • Should iteration count be implemented there? In other commands, it's supposed to decrease memory usage, but this command operates on a simple array containing content IDs and version counter only. Each ContentInfo object is loaded within the loop, so it's always only one at the time.

TODO:

  • Implement feature.
  • Fix new code according to Coding Standards ($ composer fix-cs).
  • Ask for Code Review.

@adamwojs
Copy link
Member

Should iteration count be implemented there? In other commands, it's supposed to decrease memory usage, but this command operates on a simple array containing content IDs and version counter only. Each ContentInfo object is loaded within the loop, so it's always only one at the time.

I think so, but the best way to find the answer will be to run command on some large database. Can you help @alongosz / @vidarl with this ?

@kmadejski
Copy link
Member Author

@adamwojs thanks, requested changes are done in 7337b0d

@kmadejski kmadejski changed the title [WIP] EZP-29451: As an Administrator I want to have a CLI command for database cleanup EZP-29451: As an Administrator I want to have a CLI command for database cleanup Sep 4, 2018
@kmadejski
Copy link
Member Author

Travis issue is already fixed. Could you please review @vidarl / @andrerom?

Copy link
Member

@vidarl vidarl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me, but maybe invalid values for --keep option should throw InvalidArgumentException too?

@kmadejski kmadejski force-pushed the ezp_29451 branch 2 times, most recently from fbc534b to 5a90c66 Compare September 13, 2018 13:56
@kmadejski
Copy link
Member Author

@vidarl thanks, added $keep check in 5a90c66.

@adamwojs / @andrerom / @alongosz do you see anything else to improve here?

@kmadejski
Copy link
Member Author

kmadejski commented Sep 14, 2018

Thanks @alongosz. All requested changes are done in f843198.

Copy link
Member

@konradoboza konradoboza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good to me, basic tests went ok. 👍

@micszo micszo self-assigned this Oct 3, 2018
@kmadejski
Copy link
Member Author

@micszo fixed what you've found. Could you please do a second round of tests?

@ezsystems ezsystems deleted a comment from ezrobot Dec 18, 2018
@micszo micszo assigned m-tyrala and unassigned micszo Dec 19, 2018
@kmadejski
Copy link
Member Author

@m-tyrala covered a case with keep = 0, please check once again.

Copy link

@m-tyrala m-tyrala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA approve 🚀

@m-tyrala m-tyrala removed their assignment Dec 19, 2018
@lserwatka lserwatka merged commit b74cd70 into ezsystems:6.7 Dec 19, 2018
@lserwatka
Copy link
Member

@DominikaK we need a few bits of doc here


$this
->setName('ezplatform:content:cleanup-versions')
->setDescription('Remove unwanted content versions. It keeps published version untouched. By default, it keeps also the last archived/draft version.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nipick: 'unwanted' is not the best term to use here: it is not descriptive of what it is considered unwanted

'keep',
'k',
InputOption::VALUE_OPTIONAL,
"Sets number of the most recent versions (both drafts and archived) which won't be removed.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure having 1 value for the sum of both archived versions and drafts makes a lot of sense here.
I generally operate on the basis of "keep the last 4 archived versions", "keep all drafts", "keep no drafts".
I see no reason for anyone ever wanting to keep only the 4 most recent drafts, or, even weirder, the 4 most recent drafts-or-archives

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ps: my bad, reading the code it seems that the number of versions to keep is not a sum, which makes a lot more sense. Maybe the help text could be improved a bit to explain this more clearly ?

const VERSION_DRAFT = 'draft';
const VERSION_ARCHIVED = 'archived';
const VERSION_PUBLISHED = 'published';
const VERSION_ALL = 'all';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: replace 'all' with something akin to 'all-except-published'

@gggeek
Copy link
Contributor

gggeek commented May 17, 2019

Q: does ez5 have a mechanism to automatically purge drafts older than X days? If not, it would be a nice addition. Adding an option to this command to operate on a basis of last-modified besides the max-items to keep would allow it to be used for such scenarios

# for free to join this conversation on GitHub. Already have an account? # to comment
Development

Successfully merging this pull request may close these issues.

10 participants