import_ms2gallery.php

Gallery3x2 min readPage 16 of 22
On this page 3

The script moves images from ms2Gallery (MODX 2) to Gallery3x. The ms2Gallery package may already be removed — only its <prefix>ms2_resource_files table and the files on disk are needed.

What is transferred

  • All originals (records with parent = 0) of all resources; ms2Gallery thumbnails are not needed — Gallery3x generates its own.
  • Each file is uploaded by the regular Gallery3x processor: your settings apply (file names, format, filters, watermark, media source by template).
  • Title, description, alt, active flag and order (rank → position).

Running

  1. Back up the database and the image folder.
  2. Open core/components/gallery3x/cli/import_ms2gallery.php: at the top of the file $isDryRun = true; — dry run mode, nothing is changed.
  3. From the site root, do a dry run and check the list of files found:
php core/components/gallery3x/cli/import_ms2gallery.php
MODX Initialized. Starting ms2Gallery import...
DRY RUN MODE: Files will be listed but not imported.

Found 150 files to process.
...
DRY RUN FINISHED. Found 150 files to be imported.
  1. Set $isDryRun = false;, save the file and run the same command again.
Processing file for resource ID 12: /path/to/site/assets/images/products/12/photo1.jpg
 -> SUCCESS: Imported to Gallery3x file ID 210
...
SUCCESS: Imported 150 of 150 found files.
Site cache has been cleared.

Files missing on disk are skipped with the warning WARNING: Source file does not exist.

Running the real import again uploads the files again (duplicates). Run the import once; if it fails, delete what was imported — for example with the clear_by_template.php script — and repeat.

After the import

  • Check the “Gallery G3x” tab of a few resources and the output on the site.
  • When everything is fine, the ms2_resource_files table and the old files can be deleted manually.
  • The script works from the console only: over HTTP it returns 403.