Jump to content

RockMigrations - Easy migrations from dev/staging to live server (AND MUCH MORE!!)


bernhard

Recommended Posts

v0.0.63

Thx to the feedback of @wbmnfktr I've made it a lot easier to get started with RockMigrations!

The readme has now a dedicated quickstart section: https://github.com/BernhardBaumrock/RockMigrations#quickstart

The example that was shipped with RockMigrations was also improved. I removed some complexity and used real world example names (a simple blog setup) instead of "foo" and "bar". This should make it a lot easier to understand 🙂 

Also I improved the page name replacements feature introduced lately: Page name replacements now ship with the module. They are saved in a dedicated folder and named "de.txt" for german replacements. If you need any other replacement options just let me know! (maybe @apeisa ? )

$rm->setPagenameReplacements("de");

https://github.com/BernhardBaumrock/RockMigrations/tree/master/replacements

  • Like 4
Link to comment
Share on other sites

  • 5 weeks later...

I love the module! 

I was wondering how do you handle creating a page reference field when the templates and pages are created in the same migration. Because you don't know the id's yet.

'fields' => [
	'pageSelect' => [
		'type' => 'page',
        'template_id' => XX, //template ID (foo-template to be created)
        'parent_id' => XX // Parent ID (parent-foo to be created),
        'inputfield' => 'InputfieldAsmSelect',
 	],
 ],

'templates' => [
    'foo-template',
	'parent-foo-template',
 ],

 

  • Like 1
Link to comment
Share on other sites

If execution order is important you can always use the declarative syntax:

$p1 = $rm->createPage(...);
$p2 = $rm->createPage(...);
$p2->setAndSave('pageref', $p1);

does that help?

Link to comment
Share on other sites

1 minute ago, bernhard said:

If execution order is important you can always use the declarative syntax:


$p1 = $rm->createPage(...);
$p2 = $rm->createPage(...);
$p2->setAndSave('pageref', $p1);

does that help?

Kind of

How would it work for field settings?

Link to comment
Share on other sites

1 minute ago, bernhard said:

$rm->setFieldData(...)

Best docs we have so far is using intellisense of your IDE and looking into the code 🙂 

gbWV4Tk.png

🙌 thanks

Link to comment
Share on other sites

v0.0.64 adds a new method

$rm->createViewFile('yourtemplate');

that creates a file /site/templates/yourtemplate.php

That might sound like overkill, but when used with class constant and OOP that makes it clear and easy:

<?php namespace RockTeam;

use ProcessWire\Page;
use ProcessWire\RockMigrations;
use ProcessWire\RockTeam;

class TeamPage extends Page {

  const prefix = RockTeam::prefix;
  const tpl = self::prefix."teampage";
  const tags = RockTeam::tags;

  /**
   * Triggered in RockTeam::migrate()
   */
  public function migrate(RockMigrations $rm) {
    $rm->migrate([
      'templates' => [
        self::tpl => [
          'tags' => self::tags,
          'icon' => 'users',
          'fields' => ['title'],
        ],
      ],
    ]);
    $rm->createViewFile(self::tpl);
  }

}

 

  • Like 2
Link to comment
Share on other sites

Hi Ivan,

good question 🙂 My workflow is based on RockUikit - a module for Frontend Development similar to WireFrame. So I need the file solely for making the site visible on the frontend. Markup is placed in a different location. Now that you are asking I realize that this might not be the most helpful addition for others. Anyhow I'm just keeping you updated so maybe someone will pick up some inspiration or have suggestions or input for me 🙂 

But in general my workflow is now a little bit like "everything is a module" 😅 And RockMigrations does everything related to template/field/page creation 🙂 

  • Like 1
Link to comment
Share on other sites

Most of the time I do not have anything in template file other than the namespace too as I use it as a controller. And unlike Wireframe I do need this file to avoid error, so this is not useless addition.

  • Like 1
Link to comment
Share on other sites

Actually it already has a second parameter to provide a file to take the content from. This means you could add a skeleton folder to your module holding the initial markup and the module will copy that content to the templates folder: https://github.com/BernhardBaumrock/RockMigrations/blob/3844b697be393b98dbc9a47b55370c4fa521c20b/RockMigrations.module.php#L1817

One could also make it sync files or add the file having a single "include" to reference the markup from within a module folder. But I didn't want to overcomplicate things 🙂 

  • Like 1
Link to comment
Share on other sites

You can set any file that exists and is readable on your server already...

$rm->createViewFile("mytemplate.php", "/path/to/your/source/file.php");

 

Link to comment
Share on other sites

  • 3 weeks later...

v0.0.67 has a fix to setModuleConfig method that might change how existing implementations work:

$rm->setModuleConfig("AdminThemeUikit", [
	'maxWidth' => 0, // use full width of screen
]);

Before the fix from today this code would have reset any other module settings (like a custom logoURL). No it does only update the maxWidth setting (as it merges existing config data). If you want the old behaviour you can set the third parameter to TRUE:

$rm->setModuleConfig("AdminThemeUikit", [
	'maxWidth' => 0, // use full width of screen
], TRUE);

 

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
On 3/11/2021 at 10:42 AM, bernhard said:

Whenever I don't know the code for a migration I simply create the field and have a look at Tracys field code panel:

IzoRwd4.png

 

Just a couple of quick questions - and I know this might be more of a question for Tracy Debugger itself but - why can't I see "Field Code" in my Request tab? 

Edit: sorry, found it! Tracy settings > Request info panel > Panel sections if anyone else was wondering.

Is there any other useful things I should turn on in Tracy for copying field data and similar?? 😄 

And second question please, how do I add a field to a template and have it be inside a Fieldset Tab?

Thanks in advance!

Link to comment
Share on other sites

21 hours ago, cjx2240 said:

Is there any other useful things I should turn on in Tracy for copying field data and similar?? 😄 

dont think so 😉 

21 hours ago, cjx2240 said:

And second question please, how do I add a field to a template and have it be inside a Fieldset Tab?

Usually I do that via hooking ProcessPageEdit::buildForm and the wrapFields method of RM

<?php
$this->addHookAfter("ProcessPageEdit::buildForm", function(HookEvent $event) {
    $page = $event->process->getPage();
    if($page->template != "yourtemplate") return;
    $form = $event->arguments(0);
	$rm = $event->modules->get("RockMigrations");
	$rm->wrapFields($form, ['field1', 'field2'], [
      'label' => 'your fieldset label',
      'icon' => 'bolt',
    ]);
});

 

  • Like 2
Link to comment
Share on other sites

  • 5 weeks later...

I'm looking forward to using your module Bernhard. I have written an application in ProcessWire over the past year, and 3 months into development I started kicking myself for not starting from a multi-site perspective. Now with this I can see a solid workflow for migrations whilst benefiting from keeping users locked in their own instances.

Having now read the docs I'm keen to try it out with a single new feature that will require several templates, fields and pages!

  • 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
  • Recently Browsing   0 members

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