Skip to content

Commit

Permalink
Do not create index.json file on export (#2396)
Browse files Browse the repository at this point in the history
* Do not create index.json file on export

* PHPCS fix

* PHPCS fix
  • Loading branch information
Neil Hastings authored Jul 24, 2020
1 parent 0c8f133 commit 64a8b99
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
57 changes: 27 additions & 30 deletions docroot/modules/custom/va_gov_content_export/src/TomeExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Session\AccountSwitcherInterface;
use Drupal\file\FileInterface;
use Drupal\tome_sync\Event\ContentCrudEvent;
use Drupal\tome_sync\Event\TomeSyncEvents;
use Drupal\tome_sync\Exporter;
use Drupal\tome_sync\FileSyncInterface;
use Drupal\tome_sync\TomeSyncHelper;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Serializer\Serializer;
use Drupal\Core\Entity\ContentEntityInterface;
Expand All @@ -19,13 +22,6 @@
*/
class TomeExporter extends Exporter {

/**
* File System.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;

/**
* An array of excluded entity types.
*
Expand Down Expand Up @@ -66,8 +62,6 @@ class TomeExporter extends Exporter {
* The account switcher.
* @param \Drupal\tome_sync\FileSyncInterface $file_sync
* The file sync service.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system interface.
* @param \Drupal\va_gov_content_export\AddBreadcrumbToEntity $addBreadcrumbToEntity
* The BreadcrumbEntity Manager.
*/
Expand All @@ -78,13 +72,11 @@ public function __construct(
EventDispatcherInterface $event_dispatcher,
AccountSwitcherInterface $account_switcher,
FileSyncInterface $file_sync,
FileSystemInterface $file_system,
AddBreadcrumbToEntity $addBreadcrumbToEntity
) {
parent::__construct($content_storage, $serializer, $entity_type_manager,
$event_dispatcher, $account_switcher, $file_sync);

$this->fileSystem = $file_system;
$this->addBreadcrumbToEntity = $addBreadcrumbToEntity;
}

Expand All @@ -99,31 +91,36 @@ public function exportContent(ContentEntityInterface $entity) {
return;
}

// We override all of the parent export to not create the index file.
$this->switchToAdmin();
$this->addBreadcrumbToEntity->alterEntity($entity);
parent::exportContent($entity);
$data = $this->serializer->normalize($entity, 'json');
$this->contentStorage->write(TomeSyncHelper::getContentName($entity), $data);

if ($entity instanceof FileInterface) {
$this->fileSync->exportFile($entity);
}
$event = new ContentCrudEvent($entity);
$this->eventDispatcher->dispatch(TomeSyncEvents::EXPORT_CONTENT, $event);
$this->switchBack();
}

/**
* Acquires a lock for writing to the index.
*
* @return resource
* A file pointer resource on success.
* {@inheritdoc}
*
* @throws \Exception
* Throws an exception when the index file cannot be written to.
*
* @TODO rework this error logic since this can cause a node not to save.
* Overriding to remove the updating of the index file.
*/
protected function acquireContentIndexLock() {
$destination = $this->getContentIndexFilePath();
$directory = dirname($destination);
// Overridden to allow the drupal file system to create the directory.
$this->fileSystem->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY);
$handle = fopen($destination, 'c+');
if (!flock($handle, LOCK_EX)) {
throw new \Exception('Unable to acquire lock for the index file.');
public function deleteContentExport(ContentEntityInterface $entity) {
// It would be cool if hook_entity_translation_delete() is invoked for
// every translation of an entity when it's deleted. But it isn't. :-(.
foreach (array_keys($entity->getTranslationLanguages()) as $langcode) {
$this->contentStorage->delete(TomeSyncHelper::getContentName($entity->getTranslation($langcode)));
}
if ($entity instanceof FileInterface) {
$this->fileSync->deleteFileExport($entity);
}
return $handle;
$event = new ContentCrudEvent($entity);
$this->eventDispatcher->dispatch(TomeSyncEvents::DELETE_CONTENT, $event);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
tome_sync.exporter.va_gov_content_export:
class: Drupal\va_gov_content_export\TomeExporter
decorates: tome_sync.exporter
arguments: ['@tome_sync.storage.content', '@serializer', '@entity_type.manager', '@event_dispatcher', '@account_switcher', '@tome_sync.file_sync', '@file_system', '@va_gov.content_export.breadcrumb_update']
arguments: ['@tome_sync.storage.content', '@serializer', '@entity_type.manager', '@event_dispatcher', '@account_switcher', '@tome_sync.file_sync', '@va_gov.content_export.breadcrumb_update']
va_gov.content_export.breadcrumb_update:
class: Drupal\va_gov_content_export\AddBreadcrumbToEntity
arguments: ['@breadcrumb', '@router.route_provider', '@paramconverter_manager', '@graphql.buffer.subrequest', '@current_route_match']
Expand Down

1 comment on commit 64a8b99

@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-1595611211678/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.148s
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
Fri, 24 Jul 2020 17:20:16 GMT axe-webdriverjs deprecated Error must be handled as the first argument of axe.analyze. See: #83 at tests/accessibility/aXeAccessibilityCheck.js:45:14
Fri, 24 Jul 2020 17:20:23 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-34-32
  • In: 02:26

Please sign in to comment.