Skip to content

Commit

Permalink
Add drush job to clear out old revisions (#2283)
Browse files Browse the repository at this point in the history
* Add drush job to clear out old revisions

* phpcs fixes

* Remove extra log message

* Only remove revisisonsf rom 1884
  • Loading branch information
Neil Hastings authored Jul 15, 2020
1 parent 863ebdb commit 8791596
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions docroot/modules/custom/va_gov_migrate/va_gov_migrate.drush.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* @file
* Drush jobs to clean up old revisions.
*/

use Drupal\Core\Entity\EntityStorageException;
use Drush\Log\LogLevel;

/**
* Implements hook_drush_command().
*/
function va_gov_migrate_drush_command() {
$items = [];

$items['va-gov-clean-revs'] = [
'description' => 'Clean up bad node revisions',
'aliases' => ['vg-cr'],
];

return $items;
}

/**
* Command for cleaning up revisions.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
function drush_va_gov_migrate_va_gov_clean_revs() {
$time = 1572551719;

$query = \Drupal::database()->select('node_revision', 'nr');
$query->condition('revision_timestamp', $time);
$query->fields('nr', ['vid']);
$vids = $query->execute()->fetchCol();

$query = \Drupal::database()->select('node_revision', 'nr');
$query->condition('revision_log', 'Update of status by migration.');
$query->condition('nid', 1884);
$query->fields('nr', ['vid']);
$more_vids = $query->execute()->fetchCol();

$vids = array_merge($vids, $more_vids);

drush_log('Attempting to Delete ' . count($vids) . ' node revisions', LogLevel::INFO);
$missed_vids = [];
foreach ($vids as $vid) {
try {
drush_log('Deleting: ' . $vid, LogLevel::INFO);
\Drupal::entityTypeManager()->getStorage('node')->deleteRevision($vid);
}
catch (EntityStorageException $e) {
drush_log('Vid ' . $vid . ' could not be deleted: ' . $e->getMessage(), LogLevel::WARNING);
$missed_vids[] = $vid;
}
}

$count = count($vids) - count($missed_vids);
drush_log('Deleted ' . $count . ' revision', LogLevel::OK);
drush_log('The following revisions were not deleted: ' . implode(', ', $missed_vids), LogLevel::WARNING);
}

1 comment on commit 8791596

@va-cms-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ Test Failed: va/tests/accessibility
composer va:test:accessibility
> [email protected] install /var/www/cms/node_modules/phantomjs-prebuilt
> node install.js

PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving...

Received 22866K total.
Extracting tar contents (via spawned process)
Removing /var/www/cms/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1594837346715/phantomjs-2.1.1-linux-x86_64 -> /var/www/cms/node_modules/phantomjs-prebuilt/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /var/www/cms/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs

> [email protected] postinstall /var/www/cms/node_modules/core-js
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
> https://opencollective.com/core-js 
> https://www.patreon.com/zloirock 

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

added 134 packages from 190 contributors and audited 134 packages in 12.627s
found 3 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details

> [email protected] test /var/www/cms
> node ./tests/accessibility/aXeAccessibilityCheck.js

!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com 1
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/sections  = 0
[]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/page  = 2
[ { id: 'duplicate-id',
    impact: 'minor',
    tags: [ 'cat.parsing', 'wcag2a', 'wcag411' ],
    description: 'Ensures every id attribute value is unique',
    help: 'id attribute value must be unique',
    helpUrl:
     'https://dequeuniversity.com/rules/axe/3.3/duplicate-id?application=webdriverjs',
    nodes: [ [Object], [Object] ] },
  { id: 'label',
    impact: 'critical',
    tags:
     [ 'cat.forms',
       'wcag2a',
       'wcag332',
       'wcag131',
       'section508',
       'section508.22.n' ],
    description: 'Ensures every form element has a label',
    help: 'Form elements must have labels',
    helpUrl:
     'https://dequeuniversity.com/rules/axe/3.3/label?application=webdriverjs',
    nodes: [ [Object] ] } ]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/landing_page  = 0
[]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/documentation_page  = 1
[ { id: 'label',
    impact: 'critical',
    tags:
     [ 'cat.forms',
       'wcag2a',
       'wcag332',
       'wcag131',
       'section508',
       'section508.22.n' ],
    description: 'Ensures every form element has a label',
    help: 'Form elements must have labels',
    helpUrl:
     'https://dequeuniversity.com/rules/axe/3.3/label?application=webdriverjs',
    nodes: [ [Object] ] } ]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/event  = 0
[]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/health_care_local_facility  = 1
[ { id: 'label',
    impact: 'critical',
    tags:
     [ 'cat.forms',
       'wcag2a',
       'wcag332',
       'wcag131',
       'section508',
       'section508.22.n' ],
    description: 'Ensures every form element has a label',
    help: 'Form elements must have labels',
    helpUrl:
     'https://dequeuniversity.com/rules/axe/3.3/label?application=webdriverjs',
    nodes:
     [ [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object] ] } ]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/health_care_region_detail_page  = 2
[ { id: 'duplicate-id',
    impact: 'minor',
    tags: [ 'cat.parsing', 'wcag2a', 'wcag411' ],
    description: 'Ensures every id attribute value is unique',
    help: 'id attribute value must be unique',
    helpUrl:
     'https://dequeuniversity.com/rules/axe/3.3/duplicate-id?application=webdriverjs',
    nodes: [ [Object], [Object] ] },
  { id: 'label',
    impact: 'critical',
    tags:
     [ 'cat.forms',
       'wcag2a',
       'wcag332',
       'wcag131',
       'section508',
       'section508.22.n' ],
    description: 'Ensures every form element has a label',
    help: 'Form elements must have labels',
    helpUrl:
     'https://dequeuniversity.com/rules/axe/3.3/label?application=webdriverjs',
    nodes: [ [Object] ] } ]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/health_care_region_page  = 0
[]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/office  = 0
[]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/outreach_asset  = 0
[]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/person_profile  = 0
[]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/press_release  = 1
[ { id: 'aria-allowed-attr',
    impact: 'critical',
    tags: [ 'cat.aria', 'wcag2a', 'wcag412' ],
    description: 'Ensures ARIA attributes are allowed for an element\'s role',
    help: 'Elements must only use allowed ARIA attributes',
    helpUrl:
     'https://dequeuniversity.com/rules/axe/3.3/aria-allowed-attr?application=webdriverjs',
    nodes: [ [Object] ] } ]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/regional_health_care_service_des  = 0
[]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/news_story  = 0
[]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/node/add/support_service  = 0
[]
!!!  NUMBER OF NEW VIOLATIONS on http://internal-dsva-vagov-staging-cms-1188006.us-gov-west-1.elb.amazonaws.com/user  = 1
[ { id: 'color-contrast',
    impact: 'serious',
    tags: [ 'cat.color', 'wcag2aa', 'wcag143' ],
    description:
     'Ensures the contrast between foreground and background colors meets WCAG 2 AA contrast ratio thresholds',
    help: 'Elements must have sufficient color contrast',
    helpUrl:
     'https://dequeuniversity.com/rules/axe/3.3/color-contrast?application=webdriverjs',
    nodes:
     [ [Object], [Object], [Object], [Object], [Object], [Object] ] } ]
!!!  VIOLATION TYPES FOUND: 9 PROCESS EXITED WITH CODE 1  !!!
> npm install --only=production
> npm test
Wed, 15 Jul 2020 18:22:31 GMT axe-webdriverjs deprecated Error must be handled as the first argument of axe.analyze. See: #83 at tests/accessibility/aXeAccessibilityCheck.js:45:14
Wed, 15 Jul 2020 18:22:41 GMT axe-webdriverjs deprecated Error must be handled as the first argument of axe.analyze. See: #83 at tests/accessibility/aXeAccessibilityCheck.js:57:42
npm ERR! Test failed.  See above for more details.
Script npm test handling the va:test:accessibility event returned with error code 1
  • On: ip-10-247-35-4
  • In: 02:48

Please sign in to comment.