jimbojsb / craft-db-snapshot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add an option to timestamp filename

ockam opened this issue · comments

Thanks for this nice package!

Would it be possible to add an option to timestamp the snapshot filename?

Either through a checkbox where the plugin would manage the timestamp internally
or
through twig expressions on the filename config, as in: db_snapshot_{now|date('Y')}_{now|date('m')}.sql

Found this method that could help parse the string if you choose option 2:

https://docs.craftcms.com/api/v3/craft-web-view.html#method-renderstring

After further digging, in the console controller (at line 48), you could replace

        $tmpFile = "$tmpPath/$settings->filename";
        $volumeFile = $settings->filename;

with

        $view = Craft::$app->getView();
        $filename = $view->renderString($settings->filename);

        $tmpFile = "$tmpPath/$filename";
        $volumeFile = $filename;

This would correctly parse the following: db_snapshot_{{now|date("Ymd-His")}}.sql

That's pretty easy to implement. Might try to cook it up this weekend. I'll also accept a PR for this if you want to take a crack at it.

feature is available in 1.1.0