Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

YALB-1550: Single Content Sync #409

Merged
merged 2 commits into from
Sep 18, 2023
Merged

Conversation

dblanken-yale
Copy link
Contributor

@dblanken-yale dblanken-yale commented Aug 31, 2023

YALB-1550: Single Content Sync

Description of work

  • Add single content sync and supporting functionality around it for successful exporting of content/media/taxnonomy via views
  • Patch ZipArchive for single content sync
  • Create export code for media and taxonomy terms
  • Creates new views for nodes, media, and taxonomy off of /config/system to assist in graphical exports

Functional testing steps:

Via drush

  • Bring this repo local and run composer update single_content_sync
  • In comand line:
    • Exporting
      • Run the following command: lando drush content:export nodes ./exports --translate --assets
      • Note the directory location of the zip, specifically after /app/web/
      • Note that in a real world example, you'd copy this file out and copy it to a new site under /web somewhere, noting the location to use in the drush import command.
      • Go onto the website and delete a node--make note of the node you deleted so you can verify that it was re-imported later.
    • Importing
      • In command line, type lando drush content:import ./exports/<name_of_the_zip_file_that_was_made>
      • Verify that after a little bit, you see [notice] Message: Successfully imported the content. and received no errors.
      • Visit the site and look for the node you deleted.
    • Do the same for media: lando drush content:export media ./export --assets --translate
    • Do the same for taxonomy terms: lando drush content:export taxonomy_term ./export --assets --translate

The reason the --all-content flag is not used is that it includes block_content as well. If we'd like that, then --all-content could be passed to the first node version and it would return them all. Technically since the UUIDs would be the same, it should be ok, but I'd be more explicit of what we're targeting.

Via site

  • Log in as the administrator
  • Visit Configuration->System->Export Node
  • Verify that Export content is in the Action drop down at the bottom of the listing
  • Visit Configuration->System->Export Node->Export Media
  • Verify that Export media is in the Action drop down at the bottom of the listing
  • Visit Configuration->System->Export Node->Export Taxonomy
  • Verify that Export taxonomy is in the Action drop down at the bottom of the listing
  • Feel free to export any of those three to verify that they work.
    • Click on any of the above views
    • Click multiple check boxes in the list to select those items to export
    • Ensure the Export X is selected for the bulk action and click the Apply to selected items button
    • A link should be generated in the message back to the user. Click the link to download the zip file of what you selected.
  • In an incognito browser, visit the site and log in as a CAS user
  • Verify that you cannot see any mention of imports or export links

Importing

Due to the size of the content zips, importing should be done via Drush

@github-actions
Copy link

Visit Site

Created multidev environment pr-409 for yalesites-platform.

@dblanken-yale dblanken-yale force-pushed the YALB-1550-single_content_sync branch from c74ee8f to 20632c5 Compare September 1, 2023 19:55
@dblanken-yale dblanken-yale marked this pull request as ready for review September 1, 2023 20:22
@dblanken-yale
Copy link
Contributor Author

dblanken-yale commented Sep 1, 2023

I have 2 worries:

  1. In order to not have the new Taxonomy view present, I hung the permissions on an already existing permission: export configuration
  2. Including ys_starterkit as part of the config split for starterkit; since we need it enabled by default, I almost feel we should temporarily break the specifics into a temporary module that we would then migrate into ys_starterkit once we're certain it can be retired. Right now it's included or else the export media and taxonomy are available to non-admins. :(

@vinmassaro
Copy link
Contributor

There's work being done for drush import/export in this issue. Do we need our own Drush commands?

@dblanken-yale
Copy link
Contributor Author

Oh yeah you're right! They're controlling the entity type so that was the only thing I thought of as to why we'd need to keep mine, but they've already thought of it. Ya I'll take it out.

Copy link
Contributor

@codechefmarc codechefmarc left a comment

Choose a reason for hiding this comment

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

Most of this worked great, but a few issues:

  • The Manage All Taxonomy view was still there after I disabled the Starterkit config config split, I think because that config is in /config/sync and not /config/starterkit_config
  • I was able to import smaller exports no problem (taxonomy terms) but even just a few nodes zipped into a 126MB zip caused my local and Pantheon to not accept the file. I got an Ajax error in the console:

Local:

An AJAX HTTP error occurred.
HTTP Result Code: 413
Debugging information follows.
Path: /admin/content/import?element_parents=upload_fid&ajax_form=1
StatusText: error
ResponseText: 
413 Request Entity Too Large
413 Request Entity Too Large
nginx
"

Pantheon:

"An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /admin/content/import?element_parents=upload_fid&ajax_form=1
StatusText: error
ReadyState: 0"

@dblanken-yale
Copy link
Contributor Author

@codechefmarc For the first point, I am so glad you said that. My biggest worry was hanging the permissions of the "Manage All Taxonomy" on another permission set in order to attempt to hide it, but I can just include it in the config split! I never even thought of the fact that it has a yaml config! DUH!

As for the other, I've not had that issue, but did mostly do my testing locally, and I bet for the multi devs I did small sets of files. ☹️ I'll have to dive into that more as well.

Thank you so much for this info. I'll get to work on it.

@dblanken-yale dblanken-yale force-pushed the YALB-1550-single_content_sync branch from eef3ede to eae3edc Compare September 6, 2023 13:23
@dblanken-yale
Copy link
Contributor Author

It looks as if we have some limits on the file size uploads both in nginx and in PHP. Locally using lando, nginx looks to be limiting to 80M, while PHP is limiting to 100M. I'm very confused as that means my uploads must have been less than 80M? I could have swore I went higher.

In any event, the uploads are indeed being limited by nginx, resulting in a 413: Request Entity Too Large. I'm looking into if we can fix this with a .htaccess modification or if we have to look into overloading the php.ini/nginx.conf.

@codechefmarc
Copy link
Contributor

If this is the file size limit for uploads, perhaps we can get around this by doing the hosting of the zips on S3 or via another repo and importing from those places instead of a direct upload? That may be some custom code, but, would be fun to figure that one out. (Well for fun for some!)

@dblanken-yale
Copy link
Contributor Author

@vinmassaro contacted me and wanted me to check out the status of the drush commands they're working on. If it's good enough, we might be able to get around it for now using drush. But I bet that's why they implemented the S3 feature. haha

It looks like their drush command works similarly to mine where it exports to a directory and we have to go get it. The import needs to be accessible by the web root to import. I am still going to look more into it. I've not dealt with S3 so it'd be neat to try if this doesn't get us there.

@dblanken-yale
Copy link
Contributor Author

Great news! I was able to get drush debugging done, and noticed that it was erroring on the local files directory (permissions maybe?). In any event, I wiped completely and did a fresh pull with the patch and it worked! I'm rebuilding now both a yalesites dev and a dev version of yalesites.yale.edu so I can get real content from them to test it one more time. I think it's working! I'll provide instructions in the PR above when I am certain.

Copy link
Contributor

@codechefmarc codechefmarc left a comment

Choose a reason for hiding this comment

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

The drush command worked beautifully to import! I tested locally only for now (didn't want to mess up the multidev) but also question: I had to move the zip file into the web folder for it to work (I tried using a relative path outside of web but it didn't find it). So, would this take an external URL so we could do S3 / GitHub repo to store these zip files? I assume you looked into that.

@dblanken-yale
Copy link
Contributor Author

Ya that is a limitation currently--when this command was worked on, the S3 implementation hadn't been done yet, and the branch is behind that commit. My guess is that it'll be added, but for now it is only zip files within the web directory. ☹️

Currently there is a "getRealDirectory" method that is called that returns the path, but it currently doesn't account for the S3 situation.

@dblanken-yale
Copy link
Contributor Author

dblanken-yale commented Sep 8, 2023

And now that I'm looking at the implementation, it's not that the zip file can reside in S3, it's that image assets residing in S3 that are referenced by a node properly get imported (no save is attempted). So we might still need some work pointing to a URL to download a zip.

https://git.drupalcode.org/project/single_content_sync/-/merge_requests/63/diffs#161d21d70da7441b94306f7cff37f4a82306c7da_364_381

@dblanken-yale
Copy link
Contributor Author

Placing this here in case we need it ever, there was talk of a drush dl command that was dropped from Drush 9+. Some reference this example as a way to attempt to recreate this in a custom drush command if ever needed:

https://github.com/drush-ops/drush/blob/master/examples/Commands/SyncViaHttpCommands.php#L60

@dblanken-yale dblanken-yale force-pushed the YALB-1550-single_content_sync branch from 51740d6 to 6880474 Compare September 15, 2023 13:19
@dblanken-yale
Copy link
Contributor Author

@vinmassaro The changes we talked about are in place.

  • config split for this specifically has been removed
  • all user-facing views have removed the bulk export option
  • new views have been created inside of Configuration->System specifically to export nodes, media, and taxonomy
  • removed the patch as the drush command is now in the main release
  • these new views have permissions related to being able to export configs (ideally UID 1)

When you can, give it another try, and thanks for talking this through with me yesterday.

Copy link
Contributor

@vinmassaro vinmassaro left a comment

Choose a reason for hiding this comment

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

Looks great. I was able to export starterkit content and import it into a clean local install with no issue. Approved!

This update allows exporting and importing of nodes, media, and taxonomy
through either a graphical interface or through a drush command.  Keep
in mind that due to limitations of file size uploads with PHP, Pantheon,
and Drupal, importing large amounts of data should be done via Drush.

* Add single_content_sync module and enable it
* Add custom bulk actions for exporting taxonomy and media in the same
  way as nodes
* Add processors for types not handled by single_content_sync
  * Embed
  * Markup
  * SmartDate
  * ViewsBasicParams
* Add custom admin views for exporting nodes, taxonomy, and media,
  accessible through Configuration->System->Export Nodes
* Add ZipArchive patch
  *  The open method has been deprecated, and a message appears displaying
  this when attempting to export via a zip file.  This patch squelches
  this.  This has been fixed in Drupal 10.1, but is still present in
  9.5
@dblanken-yale dblanken-yale force-pushed the YALB-1550-single_content_sync branch from 00f6e3d to 7c6adff Compare September 15, 2023 21:18
@dblanken-yale dblanken-yale merged commit 9d782d5 into develop Sep 18, 2023
0 of 2 checks passed
@dblanken-yale dblanken-yale deleted the YALB-1550-single_content_sync branch September 18, 2023 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants