Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed May 6, 2024
2 parents fae7261 + 839f26f commit 7f36250
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 61 deletions.
2 changes: 1 addition & 1 deletion App/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public function wire()
{
if ($this->wire) return $this->wire;
if ($this->wire === false) return;
chdir($this->app->rootPath());
chdir($this->app->docroot());

// pw is not yet there, eg when using pw:install
if (!is_file("index.php")) return false;
Expand Down
30 changes: 18 additions & 12 deletions App/Commands/PwDownload.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
<?php namespace RockShell;
<?php

namespace RockShell;

use Symfony\Component\Console\Input\InputArgument;

class PwDownload extends Command {
class PwDownload extends Command
{

public function config() {
public function config()
{
$this
->setDescription("Download ProcessWire")
->addArgument("version", InputArgument::OPTIONAL,
"ProcessWire version (master/dev)")
;
->addArgument(
"version",
InputArgument::OPTIONAL,
"ProcessWire version (master/dev)"
);
}

public function handle() {
$path = $this->app->rootPath();
public function handle()
{
$path = $this->app->docroot();
chdir($path);
$version = $this->argument('version')
?: $this->askWithCompletion(
Expand All @@ -22,14 +29,14 @@ public function handle() {
'dev'
);
$this->write("Downloading ProcessWire($version) to $path ...");
$this->exec("wget https://github.com/processwire/processwire/archive/$version.zip");
$this->exec("wget --quiet https://github.com/processwire/processwire/archive/$version.zip");

$this->write("Extracting files...");
$this->exec("unzip -q $version.zip");

// wait for unzip to be ready
$cnt = 0;
while(!is_dir("processwire-$version") AND ++$cnt < 30) {
while (!is_dir("processwire-$version") and ++$cnt < 30) {
$this->write("waiting for unzip...");
sleep(1);
}
Expand All @@ -40,11 +47,10 @@ public function handle() {
$this->exec("rm $version.zip");
$this->exec("mv processwire-$version pwtmp");
$this->exec('find pwtmp -mindepth 1 -maxdepth 1 -exec mv -t ./ {} +');

sleep(1);
$this->exec("rm -rf pwtmp");

return self::SUCCESS;
}

}
11 changes: 6 additions & 5 deletions App/Commands/PwInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public function stepProfile()
$exists = is_dir("site-rockfrontend-main");
if (file_exists('main.zip')) $this->exec('rm main.zip');
if (!$exists && $this->confirm("Download RockFrontend Site-Profile?", true)) {
$this->exec("wget $zip");
$this->write('Downloading ...');
$this->exec("wget --quiet $zip");
$this->write('Extracting files ...');
$this->exec('unzip -q main.zip');
$this->nextStep(true, true);
Expand Down Expand Up @@ -216,7 +217,7 @@ public function stepFinish()
public function stepReloadAdmin($notice = true)
{
if ($notice) $this->info("\nLoading ProcessWire ...");
chdir($this->app->rootPath());
chdir($this->app->docroot());
include "index.php";
/** @var ProcessWire $wire */
$url = $this->host($wire->pages->get(2)->url);
Expand Down Expand Up @@ -315,8 +316,8 @@ public function fillForm($defaults = [])
if ($this->output->isVerbose()) $this->write("$name=" . implode(",", $hosts));
$value = implode("\n", $hosts);
} elseif ($name == 'admin_name') {
$label = "Enter url of your admin interface";
$value = $this->ask($label, "processwire");
$label = 'Enter url of your admin interface';
$value = $this->ask($label, $this->option('url') ?: 'processwire');
if ($this->output->isVerbose()) $this->write("$name=$value");
} elseif ($name == 'userpass_confirm') {
$value = $this->askWithCompletion($name, $options, $pass);
Expand Down Expand Up @@ -397,7 +398,7 @@ public function getStep()
$h1 = $h1->count() ? $h1->outerHtml() : '';
if ($h1 !== '<h1 class="uk-margin-remove-top">ProcessWire 3.x Installer</h1>') {
$this->write('No ProcessWire Installer found');
if (is_file($this->app->rootPath() . "index.php")) {
if (is_file($this->app->docroot() . "index.php")) {
$this->write("");
$this->error("Found index.php - aborting ...");
$this->write("");
Expand Down
14 changes: 9 additions & 5 deletions App/Commands/PwSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function handle()
{
// add gitignore
$this->write('Updating .gitignore ...');
$dst = $this->app->rootPath() . ".gitignore";
$dst = $this->app->docroot() . ".gitignore";
$write = true;
if (is_file($dst)) {
if (!$this->confirm("$dst exists - overwrite it?", false)) {
Expand All @@ -32,7 +32,7 @@ public function handle()
$split = !is_file($this->wire()->config->paths->site . "config-local.php");
if ($split and $this->confirm("Split config into config.php and config-local.php?", true)) {
$this->warn('Adding config-local.php ...');
$dst = $this->app->rootPath() . "site/config-local.php";
$dst = $this->app->rootPath() . "config-local.php";
$write = true;
if (is_file($dst)) {
if (!$this->confirm("$dst exists - overwrite it?", false)) {
Expand All @@ -48,11 +48,15 @@ public function handle()
'userAuthSalt' => $config->userAuthSalt,
'tableSalt' => $config->tableSalt,
]);
$gitignore = $this->app->rootPath() . ".gitignore";
if (!is_file($gitignore)) {
file_put_contents($gitignore, "config-local.php\n");
}
}

// update config.php
$this->write('Updating config.php ...');
$dst = $this->app->rootPath() . "site/config.php";
$dst = $this->app->docroot() . "site/config.php";
$content = file_get_contents($dst);
$stub = file_get_contents($this->stub('config.php'));
file_put_contents($dst, $content . $stub);
Expand Down Expand Up @@ -99,7 +103,7 @@ public function handle()
*/
public function removeComments()
{
$config = $this->app->rootPath() . "site/config.php";
$config = $this->app->docroot() . "site/config.php";
if (!is_file($config)) return $this->error("config.php not found");
$str = file_get_contents($config);
$str = preg_replace("#\/\*\*\n([\S\s]*?)\*\/\n#m", "", $str);
Expand All @@ -113,7 +117,7 @@ public function removeComments()
*/
public function removeSalts()
{
$config = $this->app->rootPath() . "site/config.php";
$config = $this->app->docroot() . "site/config.php";
if (!is_file($config)) return $this->error("config.php not found");
$str = file_get_contents($config);
$str = preg_replace("/Installer: Table Salt([\S\s]*?);/m", "Table Salt moved to config-local.php\n */", $str);
Expand Down
28 changes: 0 additions & 28 deletions App/Commands/Symlink.php

This file was deleted.

5 changes: 1 addition & 4 deletions App/stubs/config.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

/**
* Load local config
* Added via rockshell pw:install command.
* This makes it possible to add config.php to your git project.
* Move all secrets to config-local.php and make sure it is ignored by git.
*/
$localConfig = __DIR__."/config-local.php";
if(is_file($localConfig)) include $localConfig;
require __DIR__ . "/../../config-local.php";
3 changes: 0 additions & 3 deletions App/stubs/rs

This file was deleted.

13 changes: 11 additions & 2 deletions Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Application extends ConsoleApplication
*/
private $context = [];

private $docroot;

/**
* Path to root folder of the project having a trailing slash
* @var string $root
Expand All @@ -32,6 +34,8 @@ public function __construct($name = "RockShell", $version = null)
parent::__construct($container, $events, $version);
$this->setName($name);
$this->root = $this->normalizeSeparators(dirname(__DIR__)) . "/";
$this->docroot =
rtrim($this->root . (getenv('DDEV_DOCROOT') ?: getenv('ROCKSHELL_DOCROOT')), "/") . "/";
}

/**
Expand Down Expand Up @@ -73,6 +77,11 @@ public function context($name, $data = null)
$this->context[$name] = $data;
}

public function docroot()
{
return $this->docroot;
}

/**
* Find all command files in the current project
*
Expand All @@ -89,8 +98,8 @@ public function findCommandFiles()
{
$roots = [
$this->root . "RockShell/App/",
$this->root . "site/modules",
$this->root . "site/assets",
$this->docroot . "site/modules",
$this->docroot . "site/assets",
];
$files = array();
foreach ($roots as $root) {
Expand Down
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
Please read the docs here: https://www.baumrock.com/en/processwire/modules/rockshell/docs/

And hey, if you find it as awesome as we do, give it a virtual high-five by starring the module! 🌟😉🙌

0 comments on commit 7f36250

Please sign in to comment.