Skip to content

Commit

Permalink
fix: remove migrations from module config to prevent auto-install of …
Browse files Browse the repository at this point in the history
…RockMigrations
  • Loading branch information
BernhardBaumrock committed Mar 16, 2024
1 parent 20ed8fa commit 614dd46
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 77 deletions.
86 changes: 11 additions & 75 deletions RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ public function init()
$this->home = $this->wire->pages->get(1);

if (!is_array($this->features)) $this->features = [];
if (!is_array($this->migrations)) $this->migrations = [];


// make $rockfrontend and $home variable available in template files
$this->wire('rockfrontend', $this);
Expand Down Expand Up @@ -378,9 +376,12 @@ public function addTopBar(&$html)

/** @var RockMigrations $rm */
$less = __DIR__ . "/topbar/topbar.less";
/** @var RockMigrations $rm */
$rm = $this->wire->modules->get('RockMigrations');
if ($rm) $rm->saveCSS($less, minify: true);

if ($this->wire->modules->isInstalled("RockMigrations")) {
/** @var RockMigrations $rm */
$rm = $this->wire->modules->get('RockMigrations');
$rm->saveCSS($less, minify: true);
}
$css = $this->toUrl(__DIR__ . "/topbar/topbar.min.css", true);
$style = "<link rel='stylesheet' href='$css'>";
$html = str_replace("</head", "$style</head", $html);
Expand Down Expand Up @@ -1411,9 +1412,9 @@ public function installLessModule(Page $page)

// less module is not installed
// if rockmigrations is installed we use it to install the less module
/** @var RockMigrations $rm */
$rm = $this->wire->modules->get('RockMigrations');
if ($rm) {
if ($this->wire->modules->isInstalled("RockMigrations")) {
/** @var RockMigrations $rm */
$rm = $this->wire->modules->get('RockMigrations');
$rm->installModule("Less", "https://github.com/ryancramerdesign/Less/archive/refs/heads/main.zip");
return $this->renderLayout($page);
}
Expand Down Expand Up @@ -1662,42 +1663,6 @@ public function manifest()
return $this->manifest = $manifest;
}

public function migrate()
{
$this->migrateLess();
$this->migrateLatteTranslations();
// $this->migrateLayoutField();
}

private function migrateLatteTranslations()
{
if (!in_array("lattetranslations", $this->migrations)) return;
/** @var RockMigrations $rm */
$rm = $this->wire->modules->get('RockMigrations');
$ext = $rm->getModuleConfig('ProcessLanguageTranslator', 'extensions');
if (strpos((string)$ext, "latte") !== false) return;
$rm->setModuleConfig("ProcessLanguageTranslator", ['extensions' => "$ext latte"]);
}

private function migrateLess()
{
if (!in_array("less", $this->migrations)) return;
$rm = $this->rm();
$rm->migrate([
'fields' => [
self::field_less => [
'type' => 'textarea',
'label' => 'LESS',
'rows' => 15,
'icon' => 'css3',
'collapsed' => Inputfield::collapsedYes,
'notes' => 'This feature is experimental',
],
],
]);
$rm->addFieldToTemplate(self::field_less, 'home');
}

/**
* Minify file and return path of minified file
*/
Expand Down Expand Up @@ -2265,10 +2230,11 @@ public function rfGrow($_data, $shrink = false): string
}

/**
* @return RockMigrations
* @return RockMigrations|false
*/
public function rm()
{
if (!$this->wire->modules->isInstalled('RockMigrations')) return false;
return $this->wire->modules->get('RockMigrations');
}

Expand Down Expand Up @@ -2553,15 +2519,6 @@ public function x($translations)
return $this->getTranslation($translations);
}

public function ___install()
{
$this->init();
if ($this->rm()) $this->migrate();
// install FrontendEditing
$this->wire->modules->get('PageFrontEdit');
$this->message('Installed Module PageFrontEdit');
}

/** ##### module config ##### */

/**
Expand All @@ -2570,8 +2527,6 @@ public function ___install()
*/
public function getModuleConfigInputfields($inputfields)
{
$this->migrate();

$name = strtolower($this);
$inputfields->add([
'type' => 'markup',
Expand Down Expand Up @@ -2733,25 +2688,6 @@ private function configSettings($inputfields)
$f->showIf = 'features=topbar';
$f->notes = 'Default is 999';
$fs->add($f);

$f = $this->wire->modules->get('InputfieldCheckboxes');
$f->name = 'migrations';
$f->label = "Migrations";
$f->icon = "rocket";
$f->addOption('favicon', 'favicon - Create an image field for a favicon and add it to the home template');
$f->addOption('ogimage', 'ogimage - Create an image field for an og:image and add it to the home template');
$f->addOption('images', 'images - Create an image field for general image uploads and add it to the home template');
$f->addOption('footerlinks', 'footerlinks - Create a page field for selecting pages for the footer menu and add it to the home template');
$url = $this->wire->pages->get(2)->url . "module/edit?name=ProcessLanguageTranslator";
$f->addOption('lattetranslations', "lattetranslations - Add latte extension to translatable files in [ProcessLanguageTranslator]($url)");
$f->addOption('less', "less - Add textarea to inject custom LESS/CSS");
$f->value = (array)$this->migrations;
$f->notes = "Note that removing a checkbox does not undo an already executed migration!";
if (!$this->wire->modules->isInstalled("RockMigrations")) {
$f->prependMarkup = "<div class='uk-alert uk-alert-warning uk-margin-remove'>These features will only work if RockMigrations is installed!</div>";
$f->collapsed = Inputfield::collapsedYes;
}
$fs->add($f);
}

private function configTools(&$inputfields)
Expand Down
4 changes: 2 additions & 2 deletions docs/template-engines/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ You created a useful filter? Share it with us in the forum!

Since version 2.24.0 RockFrontend supports translatable strings in latte files!! 😎🥳

You just need to make sure that latte files are enabled in PW's translation system. RockFrontend can do that for you if you have RockMigrations installed and check the checkbox:
You just need to make sure that latte files are enabled in PW's translation system. In your PW backend search for "translator" and go to the module settings of the "Language Translator" module:

<img src=translations.png class=blur>
<img src=translator.png class=blur>

These are the three versions that you can use to translate strings in your LATTE files - choose whatever you prefer.

Expand Down
Binary file removed docs/template-engines/translations.png
Binary file not shown.
Binary file added docs/template-engines/translator.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 614dd46

Please sign in to comment.