Skip to content

Commit

Permalink
VACMS-15893 Add setup for CM Document export/import.
Browse files Browse the repository at this point in the history
  • Loading branch information
swirtSJW committed Oct 28, 2023
1 parent ea21147 commit b40edf0
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/sync/content_model_documentation.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node: 1
paragraph: 1
taxonomy: 1
modules: 1
export_location: va_gov_migrate
7 changes: 7 additions & 0 deletions docroot/modules/custom/va_gov_migrate/cm_documents/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Export directory for Content Model Documentation document exports

This directory is the temporary storage for CM Documents exported locally and
then imported to Prod. Once they have been imported on prod, they are safe to
be deleted from here.

We should be "safe" removing anything that is more than 2 weeks old (to cover thngs like Holiday code freezes).
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
uuid: 1b66dd91-8f61-45ec-9d4a-df64c3761a4b
langcode: en
type: cm_document
bundle: cm_document
id: '125'
dependencies:
config:
- cm_document.cm_document_type.cm_document
- field.field.cm_document.cm_document.field_data_pulled_from
- field.field.cm_document.cm_document.field_data_pushed_to
- field.field.cm_document.cm_document.field_diagram
- field.field.cm_document.cm_document.field_links_to_design
- field.field.cm_document.cm_document.field_links_to_research
- field.field.cm_document.cm_document.field_link_to_cms_design_system
- field.field.cm_document.cm_document.field_link_to_va_design_system
- field.field.cm_document.cm_document.field_other_links
- field.field.cm_document.cm_document.field_related_knowledgebase
- field.field.cm_document.cm_document.field_screenshots
- field.field.cm_document.cm_document.field_stakeholders
entity:
- 'user:user:efa9900b-7446-41bf-b6a9-a99287ae2235'
fields:
vid: '183'
revision_created: '1698441703'
revision_user:
target_id: '1215'
_entity: 'user:user:efa9900b-7446-41bf-b6a9-a99287ae2235'
revision_log_message: 'Adding diagram.'
status: '1'
user_id:
target_id: '1215'
_entity: 'user:user:efa9900b-7446-41bf-b6a9-a99287ae2235'
name: 'Importing site documentation'
documented_entity: site.process
notes:
value: "<h3>Exporting</h3>\r\n\r\n<p>Exporting content model documents can be done using Drush to export them as yml files.<br />\r\nThe key to exports is the entity id.</p>\r\n\r\n<ol>\r\n\t<li>Visit the config page for the module and set the machine name for the local<br />\r\n\tcustom module that you want to contain the yml files for any exported CM Documents.</li>\r\n\t<li>Create or edit a CM Document. Save your work</li>\r\n\t<li>Hover over the \"edit\" tab to reveal the id of the CM Document.</li>\r\n\t<li>In your terminal type&nbsp;drush content-model-documentation:export &lt;id&gt;<br />\r\n\tA yml file was just created in your local module. at&nbsp;&lt;local&gt;/cm_documents/&lt;page&gt;.yml</li>\r\n\t<li>Commit this export file like any other. (repeat steps as needed)</li>\r\n</ol>\r\n\r\n<h3>Importing</h3>\r\n\r\n<p>The key to importing is the alias of the exported page.</p>\r\n\r\n<h4>Import using hook_update_n()</h4>\r\n\r\n<ol>\r\n\t<li>In your local module (usually the same one that is used for saving the exports)<br />\r\n\tadd or open the .install file.</li>\r\n\t<li>Gather the aliases from the pages you want to import (not including the domain).</li>\r\n\t<li>Add the something similar to this to the .install file.</li>\r\n</ol>\r\n\r\n<blockquote>\r\n<p>/**<br />\r\n&nbsp;&nbsp;* Import some CM Documents.<br />\r\n&nbsp;&nbsp;*/<br />\r\nfunction va_gov_migrate_update_9017() {<br />\r\n&nbsp;&nbsp;$cm_documents_to_import = [&nbsp; &nbsp; &nbsp;'/admin/structure/types/manage/promo_banner/document',&nbsp; &nbsp; &nbsp; '/admin/structure/types/manage/full_width_banner_alert/document',<br />\r\n];</p>\r\n\r\n<p>// Use TRUE if it is a new CM Document.<br />\r\n// Use FALSE if its an update to an existing CM Document<br />\r\n$strict = TRUE;<br />\r\nreturn CmDocumentImport::import($cm_documents_to_import, $strict);<br />\r\n}</p>\r\n</blockquote>\r\n\r\n<p>The&nbsp;$strict&nbsp;determines whether the update is considered a failure if any of the<br />\r\nCM Documents do not import. TRUE will cause the hook_update to consider a failure if any of the imports get rejected. FALSE will allow the rejections to happen but still<br />\r\nconsider the update a success.</p>\r\n\r\n<ol>\r\n\t<li>WHen drush updb is run, the content will create new entities or update existing.</li>\r\n</ol>\r\n\r\n<p>What causes an import to get rejected?</p>\r\n\r\n<ul>\r\n\t<li>Timing. If you export a CM Document on Monday, a coworker edits the same<br />\r\n\tCM Document on Tuesday, and then you try to import your changed on Friday, they will get rejected so that your changes do not overwrite the changes made on Tuesday.</li>\r\n</ul>\r\n\r\n<h4>Import using Drush</h4>\r\n\r\n<p>If you did not want to use a hook_update_n() to deploy your changes, you can use Drush.</p>\r\n\r\n<ol>\r\n\t<li>Find the alias of the CM Document that you want to import.</li>\r\n\t<li>Use the alias in the command&nbsp;drush content-model-documentation:import '/alias/of/the/cm-document'</li>\r\n</ol>\r\n"
format: rich_text
created: '1698441103'
changed: '1698441703'
revision_translation_affected: { }
revision_default: '1'
metatag: { }
field_data_pulled_from: { }
field_data_pushed_to: { }
field_diagram:
-
title: 'Workflow for deploying documentation'
diagram: "flowchart TD\r\n A[Add your code] --> B[Write your CM Document locally]\r\n B --> C[Grab the ID of the document]\r\n C -->D[Use ID in Drush export command]\r\n D -->E[Copy the alias]\r\n E -->F[Add hook_update_n to va_gov_migrate using the alias]\r\n F -->G[Commit your code]"
caption: "The workflow is: \r\nAdd your code. Write your CM Document locally. Grab the ID of the document. Use ID in Drush export command. Copy the alias. Add hook_update_n to va_gov_migrate using the alias. Commit your code."
key: ''
show_code: '1'
field_links_to_design: { }
field_links_to_research: { }
field_link_to_cms_design_system: { }
field_link_to_va_design_system: { }
field_other_links:
-
uri: 'https://www.drupal.org/project/content_model_documentation'
title: 'Content Model Documentation module project page (same as README in the module)'
options: { }
field_related_knowledgebase: { }
field_screenshots: { }
field_stakeholders: { }
24 changes: 24 additions & 0 deletions docroot/modules/custom/va_gov_migrate/va_gov_migrate.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Update functions for the va_gov_migrate module.
*/

use Drupal\content_model_documentation\CmDocumentMover\CmDocumentImport;
use Drupal\Core\Database\Database;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\StreamWrapper\PublicStream;
Expand Down Expand Up @@ -201,3 +202,26 @@ function va_gov_migrate_update_8010() {

return $messages;
}

/**
* Update Content Model Documentation ahead of config import.
*/
function va_gov_migrate_update_9001() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('content_model_documentation.settings');
$config->set('export_location', 'va_gov_migrate');
$config->save(TRUE);
return 'Added storage location for Content Model Documentation module.';
}

/**
* Import documentation about Importing documentation.
*/
function va_gov_migrate_update_9002() {
$cm_documents_to_import = [
'/admin/structure/cm_document/process/125/importing-site-documentation',
];
// Consider using TRUE for new CM Documents, and FALSE for updating existing.
$strict = TRUE;
return CmDocumentImport::import($cm_documents_to_import, $strict);
}

0 comments on commit b40edf0

Please sign in to comment.