Jump to content

How can I automate running watched files outside of modules and custom page classes?


gornycreative
 Share

Recommended Posts

Say I define in my migrate.php:

$rm = $this->wire->modules->get('RockMigrations');
$rm->watch($this->wire->config->paths->site.'migrations',3);
$rm->watch($this->wire->config->paths->site.'migrations/matrixtypes',1);

Suppose I make a change/save/touch this file as /site/migrations/matrixtypes/meta_zone_1.php:

<?php namespace ProcessWire;
$rm = $this->wire->modules->get('RockMigrations');
$rm->setMatrixItems('meta_zone_1', [
    'profile_image_block' => [
        'label' => 'Author > Profile Image Block',
        'head' => '{matrix_type}',
        'sort' => 1,
        'fields' => [
            'profile_image_block_layout' => [
                'columnWidth' => 50,
            ],
            'profile_image_block_bio' => [
                'columnWidth' => 50,
            ],
        ],
    ],
]);

I've brought in the RepeaterMatrix functions from v1 and added the filetype test to createField - let's assume that. Manually triggered these work.

When I run $rm->getChangedFiles() I can see the saved file in the list. A change was detected.

If I run $rm->migrateWatchFiles(); the file is rendered and the repeatermatrix item is added.

I need to run that method, however, in say Tracy console for the changed files to be seen and migrated.

However, when I make changes to watched modules and pageclasses that use MagicPage the migration methods automatically run the next time I load an admin page after saving my changes.

How do I get that behavior with watched php files that aren't magicpages or in a module?

I can see that ready() in the module contains migrateWatchFiles() - I'm guessing it should be firing? If I add bd($this->getChangedFiles()); ahead of this, it always returns an empty array even though when I run the same method in Tracy it detects changes as I save different files.

Link to comment
Share on other sites

Never mind.

The simplest way to do this is include $rm->watch methods in ready.php that cover the subset I want to pay more immediate attention to and then run migrate those watched files there:

$rm = $this->wire->modules->get('RockMigrations');

$rm->watch($wire->config->paths->site.'/migrations',2);
$rm->watch($wire->config->paths->site.'/migrations/matrixtypes',1);
bd($rm->getChangedFiles()); // Just to check on things.
$rm->migrateWatchFiles();

 

  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...