SteveB Posted February 23, 2016 Share Posted February 23, 2016 ProcessAssetsBackups is a new module I've developed as an Image Archive. Why? When multiple people maintain content, sometimes updating older pages, eventually someone reports as "missing" an image which someone discarded a year ago. This archive tool explains what happened and provides the old image. Status: It's working (in 2.7.3) and provides the functionality I need for my current project but it could do more. Before I put it out in the world I'd like to know what people would like from such a module. It could archive other file based assets and do more in terms of Restore and Explore operations. In my test I've backed up about 1.5GB of images from a site with about 30,000 pages. Click a button in the page editor to see chronological listing of past and current images from the archive. Read the overview to see what we have so far. Overview:The module maintains a backup of Processwire file assets for images (not the variations, only files with one dot). The tree of archived files is positioned outside of the Processwire installation, partly for logistics of site maintenance and partly to avoid conflicts with Processwire's access control.Batching and cron are involved because of the quantity and ongoing nature of the work. To update the archive, image field table records are inspected in the order of their modified timestamps. After each batch of images the last timestamps are saved in module config so the updater knows where to resume. Cron should call this frequently.A small PHP script provides access to the archive.Cron uses it to run the updater like this: http://www.example.com/abService.php?cmd=updateTo get a report on available assets for a given page call it like this: http://www.example.com/abService.php?cmd=explore&id={$page->id};In the backend a /processwire/setup/assets-backups/ page lets you set which image fields are to be backed up. On save it resets the timestamps in the module's config info so that everything is checked.More about the archive contents:When the updater finds a new image it saves that image and also saves a small json file containing the image field's record for that image. Having the field data opens up possibilities for additional features. These json files are named by the timestamp, field name and sort value (to sort in a useful way and be unique). In most cases the image file names are unaltered. The exception is when a new replacement image has the same name as an existing image but is a different size. In that case the existing copy is suffixed with the new image's timestamp (indicating time of retirement) before the new image is copied.Access to the archive files can optionally be restricted by an .htaccess file. That rewrites URLs, sending them to the abService.php script which is setup to return content only to users who are logged in and have certain roles. Others get a 404. The script can easily be edited to return only files with certain extensions (e.g. allow images but not json files).Making use of the archive:An "Image Archive" button can be added to edit pages for templates having images. This is done by adding aRuntimeMarkup field to the page and pasting in a few lines of code to open a abService.php url in a modal.Currently this display is simply a chronological list of the images with their timestamps and filenames. If you want to revert to an earlier image you can drag and drop it to a folder on your computer and then drag and drop it from there to an image field in a page editor. Any suggestions? 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now