diff -u b/src/Form/NodeRevisionDeleteAdminSettings.php b/src/Form/NodeRevisionDeleteAdminSettings.php --- b/src/Form/NodeRevisionDeleteAdminSettings.php +++ b/src/Form/NodeRevisionDeleteAdminSettings.php @@ -126,8 +126,10 @@ $rev_recency = is_numeric($minimum_age_to_delete_number) && intval($minimum_age_to_delete_number) > 0 ? new \DateTime($minimum_age_to_delete_format) : NULL; $when_to_delete_format = $this->getConvertibleTimeFormat('when_to_delete', $when_to_delete_number); $skip_nodes_more_recently_modified_than = is_numeric($when_to_delete_number) && intval($when_to_delete_number) > 0 ? new \DateTime($when_to_delete_format) : NULL; + $reqQuery = new RevisionQuery($content_type, $minimum_revisions_to_keep, $rev_recency, $skip_nodes_more_recently_modified_than); $candidate_nodes = $reqQuery->countAffectedNodes(); + // If we have candidates nodes then we will allow to run the batch job. if ($candidate_nodes && !$exists_candidates_nodes) { $exists_candidates_nodes = TRUE; @@ -299,7 +301,12 @@ _node_revision_delete_update_time_max_number_config('when_to_delete', $when_to_delete_time_max_number); _node_revision_delete_update_time_max_number_config('minimum_age_to_delete', $minimum_age_to_delete_time_max_number); // Saving the configuration. - $this->config('node_revision_delete.settings')->set('node_revision_delete_cron', $form_state->getValue('node_revision_delete_cron'))->set('node_revision_delete_time', $form_state->getValue('node_revision_delete_time'))->set('node_revision_delete_when_to_delete_time', $node_revision_delete_when_to_delete_time)->set('node_revision_delete_minimum_age_to_delete_time', $node_revision_delete_minimum_age_to_delete_time)->save(); + $this->config('node_revision_delete.settings') + ->set('node_revision_delete_cron', $form_state->getValue('node_revision_delete_cron')) + ->set('node_revision_delete_time', $form_state->getValue('node_revision_delete_time')) + ->set('node_revision_delete_when_to_delete_time', $node_revision_delete_when_to_delete_time) + ->set('node_revision_delete_minimum_age_to_delete_time', $node_revision_delete_minimum_age_to_delete_time) + ->save(); } /** @@ -311,6 +318,7 @@ * @param $interval_number * * @return string + * * @throws \InvalidArgumentException */ protected function getConvertibleTimeFormat($config_key, $interval_number) { @@ -319,7 +327,7 @@ $config_name_time = $config->get('node_revision_delete_' . $config_key . '_time'); if (empty($config_name_time['time']) || !preg_match('/day[s]?|week[s]?|month[s]?|year[s]?/i', $config_name_time['time'])) { - throw new \InvalidArgumentException("Invalid or unknown value. We are expecting day,week,month or year"); + throw new \InvalidArgumentException("Invalid or unknown value. We are expecting day, week, month or year"); } // Is singular or plural? return sprintf('%s %s ago', $interval_number, $config_name_time['time']); diff -u b/src/RevisionQuery.php b/src/RevisionQuery.php --- b/src/RevisionQuery.php +++ b/src/RevisionQuery.php @@ -1,54 +1,57 @@ nodeInactivityAge = $nodeInactivityAge; @@ -87,24 +95,26 @@ * The Node type. * * @param string $content_type - * The node bundle. Ex. article,basic_page + * The node bundle. Ex. article,basic_page. * * @return \Drupal\node_revision_delete\RevisionQuery */ public function setType($content_type) { - // @todo: should add type validation? If the bundle doesn't exist then no harm no foul. + // @todo: Should add type validation? If the bundle doesn't exist then no + // harm no foul. $this->type = $content_type; return $this; } /** - * Sets the minimum number of revisions for each node to retain. This value will always be equal to, or greater than 1. + * Sets the minimum number of revisions for each node to retain. * - * Invalid values are ignored. This function can be chained. + * This value will always be equal to, or greater than 1. Invalid values are + * ignored. This function can be chained. * * @param int $minimum_revisions_to_keep - * The minimum number of revisions to keep for each node. + * The minimum number of revisions to keep for each node. * * @return \Drupal\node_revision_delete\RevisionQueryInterface */ @@ -123,6 +133,9 @@ return $this->nodeQuery->count(); } + /** + * {@inheritdoc} + */ public function countRemovableRevisions() { return $this->revQuery->count(); } @@ -134,7 +147,6 @@ // TODO: Implement fetchRemovable() method. } - /** * @param array $options * @@ -151,9 +163,9 @@ - //$query->groupBy('n.nid'); - - // couldn't use here havingCondition and couldn't use the num_revisions alias. May be an ORM issue. + // $query->groupBy('n.nid'); + // couldn't use here havingCondition and couldn't use the num_revisions + // alias. May be an ORM issue. $query->having('COUNT(n.nid) > :min_retain_revisions', [':min_retain_revisions' => $this->minRev]); return $query; } -} \ No newline at end of file +} diff -u b/src/RevisionQueryInterface.php b/src/RevisionQueryInterface.php --- b/src/RevisionQueryInterface.php +++ b/src/RevisionQueryInterface.php @@ -1,18 +1,14 @@ connection = \Drupal::service('database'); } + /** + * + */ public static function create() { return new static(); } -} \ No newline at end of file + +} diff -u b/src/WorkQuery/NodeWorkQuery.php b/src/WorkQuery/NodeWorkQuery.php --- b/src/WorkQuery/NodeWorkQuery.php +++ b/src/WorkQuery/NodeWorkQuery.php @@ -1,26 +1,24 @@ countRevisionSubQuery($type, $minimum_revisions_to_keep, $min_node_inactivity_age); - // initially set the revision count query as the main query. It may become a subquery + // Initially set the revision count query as the main query. It may become + // a subquery. $this->query = $subQuery; if ($min_rev_age_to_keep) { @@ -60,9 +59,10 @@ } /** - * Marking as private. The table aliases in this query are defined in the main query. + * The table aliases in this query are defined in the main query. * - * Note: This query operates on a node's CURRENT revision, which may not necessarily be a node's most recent revision. + * This query operates on a node's CURRENT revision, which may not necessarily + * be a node's most recent revision. * * @return \Drupal\Core\Database\Query\SelectInterface */ @@ -71,17 +71,19 @@ $subQuery = $this->connection->select('node_revision', 'r2'); $subQuery->addField('r2', 'revision_timestamp'); $subQuery->where('r2.vid = n.vid'); - //$subQuery->orderBy('r2.revision_timestamp', 'DESC'); - //$subQuery->range(0, 1); + // $subQuery->orderBy('r2.revision_timestamp', 'DESC'); + // $subQuery->range(0, 1);. return $subQuery; } /** - * Constructs a query that returns all the nids and their current vid based on the bundle, and the minimum revision count. + * Constructs a query that returns all the nids and their current vid. * - * @param $type - * @param $minimum_revisions_to_keep + * This is made based on the bundle, and the minimum revision count. + * + * @param $type + * @param $minimum_revisions_to_keep * @param \DateTime $min_node_inactivity_age * * @return \Drupal\Core\Database\Query\SelectInterface @@ -90,18 +92,21 @@ /** @var \Drupal\Core\Database\Query\SelectInterface $query */ $query = $this->connection->select('node', 'n'); $query->addField('n', 'nid'); - //$query->addField('n', 'vid'); + // $query->addField('n', 'vid');. $query->addExpression('COUNT(n.nid)', 'num_revisions'); $query->join('node_revision', 'r', 'n.nid=r.nid'); $query->condition('n.type', $type); if ($min_node_inactivity_age instanceof DateTime) { - // Construct a WHERE clause to filter out nodes more recent than the $min_rev_age_to_keep. Constructs a WHERE with a SELECT subquery on the CURRENT revision. + // Construct a WHERE clause to filter out nodes more recent than the + // $min_rev_age_to_keep. Constructs a WHERE with a SELECT subquery on the + // CURRENT revision. $query->condition($min_node_inactivity_age->format('U'), $this->currentRevisionTimeStampSubQuery(), '>'); } $query->groupBy('n.nid'); - // couldn't use here havingCondition and couldn't use the num_revisions alias. + // Couldn't use here havingCondition and couldn't use the num_revisions + // alias. $query->having('COUNT(n.nid) > :min_retain_revisions', [':min_retain_revisions' => $minimum_revisions_to_keep]); return $query; @@ -125,2 +130,3 @@ } + } diff -u b/src/WorkQuery/RevisionWorkQuery.php b/src/WorkQuery/RevisionWorkQuery.php --- b/src/WorkQuery/RevisionWorkQuery.php +++ b/src/WorkQuery/RevisionWorkQuery.php @@ -2,33 +2,32 @@ -/** - * @contains RevisionWorkQuery.php - * User: goce - * Date: 12/21/17 - * Time: 3:33 PM - */ namespace Drupal\node_revision_delete\WorkQuery; use DateTime; - /** - * File: RevisionWorkQuery.php - * Author: goce - * Created: 2017.12.21 * - * Description: */ class RevisionWorkQuery extends BaseWorkQuery { + /** + * + */ public function setQuery($type, $minRevRetain, DateTime $minAgeRetain) { // TODO: Implement setQuery() method. } + /** + * + */ public function count() { // TODO: Implement count() method. } + /** + * + */ public function fetchRecords() { // TODO: Implement fetchRecords() method. } -} \ No newline at end of file + +} diff -u b/src/WorkQuery/WorkQueryInterface.php b/src/WorkQuery/WorkQueryInterface.php --- b/src/WorkQuery/WorkQueryInterface.php +++ b/src/WorkQuery/WorkQueryInterface.php @@ -1,16 +1,12 @@