Skip to content

Commit

Permalink
[4.3] Add a CLI installation for Joomla (#38325)
Browse files Browse the repository at this point in the history
* Initial code for a CLI installation

* First PoC

* Lots of cleanup

* Finalising CLI installer

* Deleting install folder after installation

* Codestyle

* Fixing path of API test install

* Update installation/INSTALL

Co-authored-by: Brian Teeman <brian@teeman.net>

* Codestyle

* Docblocks

* Wording

* Fixing db prefix for API tests

* Fixing Postgres API tests

* Further fixes to API tests

* Some cleanup

* Fixing API tests one last time

* Docblock formatting

* Resorting fields

* Improving progress indicator messages

* Disable remote DB check for CLI installation

* Fixing check

* Introducing _JCLI_INSTALLATION constant for DB check

* Hiding password entries on CLI

* hide admin psw

* show db_prefix

show db_prefix in interacting mode too

* Adding check for configuration.php present

* Allowing for empty db password

* Deleting installation folder only when not in dev mode

* Codestyle

* Converting strings to ini file

* Update installation/language/en-GB/joomla.cli.ini

Co-authored-by: Brian Teeman <brian@teeman.net>

* Update installation/src/Console/InstallCommand.php

Co-authored-by: Brian Teeman <brian@teeman.net>

* Update installation/src/Console/InstallCommand.php

Co-authored-by: Brian Teeman <brian@teeman.net>

* Update installation/src/Console/InstallCommand.php

Co-authored-by: Brian Teeman <brian@teeman.net>

* Update installation/src/Console/InstallCommand.php

Co-authored-by: Brian Teeman <brian@teeman.net>

* Update installation/src/Console/InstallCommand.php

Co-authored-by: Brian Teeman <brian@teeman.net>

* Update installation/language/en-GB/joomla.cli.ini

Co-authored-by: Brian Teeman <brian@teeman.net>

* Update installation/language/en-GB/joomla.cli.ini

Co-authored-by: Brian Teeman <brian@teeman.net>

* Update installation/language/en-GB/joomla.cli.ini

Co-authored-by: Brian Teeman <brian@teeman.net>

* Update installation/language/en-GB/joomla.cli.ini

Co-authored-by: Brian Teeman <brian@teeman.net>

* Update installation/language/en-GB/joomla.cli.ini

Co-authored-by: Brian Teeman <brian@teeman.net>

* Update installation/language/en-GB/joomla.cli.ini

Co-authored-by: Brian Teeman <brian@teeman.net>

* Update installation/INSTALL

Co-authored-by: Brian Teeman <brian@teeman.net>

* Further bugfixes

* Cleaning up available RDBMS options

* Catching error when connecting to database

* Removing false db type

* Fixing case of attribute

* Removing unnecessary methods from CliInstallationApplication

* Fixing string

* Sorting translation strings for CLI and adding shortened error message

* Fixing docblocks and use statement

* Adding Allons suggestions

* Fixing use statements

* Using language object from app

* Remove unnecessary method

* Fixing language object

* Removing . at the end of sentences since they are followed by a : anyway

* Use - instead of _ in the parameters

* Fixing api tests

Co-authored-by: Brian Teeman <brian@teeman.net>
Co-authored-by: Nicola Galgano <optimus4joomla@gmail.com>
Co-authored-by: Allon Moritz <allon.moritz@digital-peak.com>
  • Loading branch information
4 people authored Oct 21, 2022
1 parent 8136847 commit f340734
Show file tree
Hide file tree
Showing 16 changed files with 940 additions and 38 deletions.
14 changes: 7 additions & 7 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ steps:
environment:
JOOMLA_INSTALLATION_DISABLE_LOCALHOST_CHECK: 1
commands:
- bash tests/Codeception/drone-api-run.sh "$(pwd)" mysql
- bash tests/Codeception/drone-api-run.sh "$(pwd)" mysql mysqli mysql jos_

- name: phpmax-api-mysql
depends_on:
Expand All @@ -226,7 +226,7 @@ steps:
environment:
JOOMLA_INSTALLATION_DISABLE_LOCALHOST_CHECK: 1
commands:
- bash tests/Codeception/drone-api-run.sh "$(pwd)" mysqlphpmax
- bash tests/Codeception/drone-api-run.sh "$(pwd)" mysqlphpmax mysqli mysql phpmax_

# - name: phpnext-api-mysql
# depends_on:
Expand All @@ -236,7 +236,7 @@ steps:
# environment:
# JOOMLA_INSTALLATION_DISABLE_LOCALHOST_CHECK: 1
# commands:
# - bash tests/Codeception/drone-api-run.sh "$(pwd)" mysqlphpnext
# - bash tests/Codeception/drone-api-run.sh "$(pwd)" mysqlphpnext mysqli mysql8 phpmax_

- name: phpmin-api-postgres
depends_on:
Expand All @@ -245,7 +245,7 @@ steps:
environment:
JOOMLA_INSTALLATION_DISABLE_LOCALHOST_CHECK: 1
commands:
- bash tests/Codeception/drone-api-run.sh "$(pwd)" postgres
- bash tests/Codeception/drone-api-run.sh "$(pwd)" postgres pgsql postgres jos_

- name: phpmax-api-postgres
depends_on:
Expand All @@ -254,7 +254,7 @@ steps:
environment:
JOOMLA_INSTALLATION_DISABLE_LOCALHOST_CHECK: 1
commands:
- bash tests/Codeception/drone-api-run.sh "$(pwd)" postgresphpmax
- bash tests/Codeception/drone-api-run.sh "$(pwd)" postgresphpmax pgsql postgres phpmax_

# - name: phpnext-api-postgres
# depends_on:
Expand All @@ -264,7 +264,7 @@ steps:
# environment:
# JOOMLA_INSTALLATION_DISABLE_LOCALHOST_CHECK: 1
# commands:
# - bash tests/Codeception/drone-api-run.sh "$(pwd)" postgresphpnext
# - bash tests/Codeception/drone-api-run.sh "$(pwd)" postgresphpnext pgsql postgres

- name: phpmin-system-mysql
depends_on:
Expand Down Expand Up @@ -524,6 +524,6 @@ trigger:

---
kind: signature
hmac: f496f213481b3afcec73da651fc838af21f76950954daac599e665ceb382cc2d
hmac: 35f71c2c3f977f0da835b27f18cea8f07419c3dd14aae4bc8da11fdb624983c5

...
27 changes: 19 additions & 8 deletions installation/INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,31 @@ INSTALLATION

and then enter 'exit' or 'quit' to exit MySQL.

3. WEB INSTALLER
3. INSTALLATION
The main method of installation is via the web browser. You can start that
installation by simply pointing your web browser to http://www.example.org
where the Joomla! web based installer will guide you through the rest of
the installation.

An alternative method of installation is from the command line. On the command line of your
server, in the root folder of Joomla, you can run the following command

php installation/joomla.php install

You will be guided through the rest of the installation and ou can get further help by running

php installation/joomla.php help install

Finally point your web browser to http://www.example.org where the Joomla! web
based installer will guide you through the rest of the installation.

4. CONFIGURE Joomla

You can now launch your browser and point it to your Joomla! site eg
You can now launch your browser and point it to your Joomla! site eg

http://www.example.org -> Main Site
http://www.example.org/administrator -> Admin
http://www.example.org -> Main Site
http://www.example.org/administrator -> Admin

You can log into Admin using the username and password that you chose
during the web based install.
You can log into Admin using the username and password that you chose
during the install.


Joomla! ADMINISTRATION
Expand Down
18 changes: 9 additions & 9 deletions installation/forms/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
class="form-control"
required="true"
/>
<field
name="admin_email"
type="email"
label="INSTL_ADMIN_EMAIL_DESC"
class="form-control"
validate="email"
required="true"
/>
<field
name="admin_user"
type="text"
Expand Down Expand Up @@ -53,12 +45,20 @@
force="on"
filter="raw"
/>
<field
name="admin_email"
type="email"
label="INSTL_ADMIN_EMAIL_DESC"
class="form-control"
validate="email"
required="true"
/>
<field
name="db_type"
type="databaseconnection"
label="INSTL_DATABASE_TYPE_DESC"
class="form-select"
supported="mysql,mysqli,pgsql,postgresql"
supported="mysql,mysqli,pgsql"
required="true"
default="mysqli"
filter="string"
Expand Down
63 changes: 63 additions & 0 deletions installation/includes/cli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* @package Joomla.Installation
* @subpackage Application
*
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

// Define the base path and require the other defines
define('JPATH_BASE', dirname(__DIR__));

require_once __DIR__ . '/defines.php';

// Check for presence of vendor dependencies not included in the git repository
if (!file_exists(JPATH_LIBRARIES . '/vendor/autoload.php') || !is_dir(JPATH_ROOT . '/media/vendor')) {
echo 'It looks like you are trying to run Joomla! from our git repository.' . PHP_EOL;
echo 'To do so requires you complete a couple of extra steps first.' . PHP_EOL;
echo 'Please see https://docs.joomla.org/Special:MyLanguage/J4.x:Setting_Up_Your_Local_Environment for further details.' . PHP_EOL;

exit;
}

// Get the framework.
require_once __DIR__ . '/framework.php';

// Check if the default log directory can be written to, add a logger for errors to use it
if (is_writable(JPATH_ADMINISTRATOR . '/logs')) {
\Joomla\CMS\Log\Log::addLogger(
[
'format' => '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}',
'text_file' => 'error.php'
],
\Joomla\CMS\Log\Log::ALL,
['error']
);
}

// Register the Installation application
JLoader::registerNamespace('Joomla\\CMS\\Installation', JPATH_INSTALLATION . '/src', false, false);

// Get the dependency injection container
$container = \Joomla\CMS\Factory::getContainer();
$container->registerServiceProvider(new \Joomla\CMS\Installation\Service\Provider\Application());

/*
* Alias the session service keys to the CLI session service as that is the primary session backend for this application
*
* In addition to aliasing "common" service keys, we also create aliases for the PHP classes to ensure autowiring objects
* is supported. This includes aliases for aliased class names, and the keys for aliased class names should be considered
* deprecated to be removed when the class name alias is removed as well.
*/
$container->alias('session', 'session.cli')
->alias('JSession', 'session.cli')
->alias(\Joomla\CMS\Session\Session::class, 'session.cli')
->alias(\Joomla\Session\Session::class, 'session.cli')
->alias(\Joomla\Session\SessionInterface::class, 'session.cli');

// Instantiate and execute the application
$container->get(\Joomla\CMS\Installation\Application\CliInstallationApplication::class)->execute();
39 changes: 39 additions & 0 deletions installation/joomla.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* @package Joomla.Installation
*
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

/**
* NOTE: This file should remain compatible with PHP 5.2 to allow us to run our PHP minimum check and show a friendly error message
*/

/**
* Define the application's minimum supported PHP version as a constant so it can be referenced within the application.
*/
define('JOOMLA_MINIMUM_PHP', '7.2.5');

if (version_compare(PHP_VERSION, JOOMLA_MINIMUM_PHP, '<')) {
echo 'Sorry, your PHP version is not supported.' . PHP_EOL;
echo 'Your command line php needs to be version ' . JOOMLA_MINIMUM_PHP . ' or newer to run the Joomla! CLI Tools' . PHP_EOL;
echo 'The version of PHP currently running this code, at the command line, is PHP version ' . PHP_VERSION . '.' . PHP_EOL;
echo 'Please note, the version of PHP running your commands here, may be different to the version that is used by ';
echo 'your web server to run the Joomla! Web Application' . PHP_EOL;

exit;
}

/**
* Constant that is checked in included files to prevent direct access.
* define() is used rather than "const" to not error for PHP 5.2 and lower
*/
define('_JEXEC', 1);

// Constant to identify the CLI installation
define('_JCLI_INSTALLATION', 1);

// Run the application - All executable code should be triggered through this file
require_once dirname(__FILE__) . '/includes/cli.php';
35 changes: 35 additions & 0 deletions installation/language/en-GB/joomla.cli.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
INSTL_ADMIN_EMAIL_DESC="Enter the email address of the website Super User"
INSTL_ADMIN_EMAIL_DESC_SHORT="Email address of the website's Super User account"
INSTL_ADMIN_PASSWORD_DESC="Set the password for your Super User account"
INSTL_ADMIN_PASSWORD_DESC_SHORT="Password of your Super User account"
INSTL_ADMIN_USERNAME_DESC="Set the username for your Super User account"
INSTL_ADMIN_USERNAME_DESC_SHORT="Username of your Super User account"
INSTL_ADMIN_USER_DESC="Enter the real name of your Super User"
INSTL_ADMIN_USER_DESC_SHORT="Real name of the Super User account"
INSTL_DATABASE_COULD_NOT_CONNECT="%s"
INSTL_DATABASE_ENCRYPTION_CA_LABEL="Path to CA file to verify encryption against"
INSTL_DATABASE_ENCRYPTION_CA_LABEL_SHORT="Path to CA file to verify encryption against"
INSTL_DATABASE_ENCRYPTION_CERT_LABEL="Path to the SSL certificate for the database connection. Requires encryption to be set to 2"
INSTL_DATABASE_ENCRYPTION_CERT_LABEL_SHORT="Path to the SSL certificate for the database connection. Requires encryption to be set to 2"
INSTL_DATABASE_ENCRYPTION_CIPHER_LABEL="Supported Cipher Suite (optional)"
INSTL_DATABASE_ENCRYPTION_CIPHER_LABEL_SHORT="Supported Cipher Suite (optional)"
INSTL_DATABASE_ENCRYPTION_KEY_LABEL="SSL key for the database connection. Requires encryption to be set to 2"
INSTL_DATABASE_ENCRYPTION_KEY_LABEL_SHORT="SSL key for the database connection. Requires encryption to be set to 2"
INSTL_DATABASE_ENCRYPTION_MODE_LABEL="Encryption for the database connection. Values: 0=None, 1=One way, 2=Two way"
INSTL_DATABASE_ENCRYPTION_MODE_LABEL="Encryption for the database connection. Values: 0=None, 1=One way, 2=Two way"
INSTL_DATABASE_ENCRYPTION_VERIFY_SERVER_CERT_LABEL="Verify SSL certificate for database connection. Values: 0=No, 1=Yes. Requires encryption to be set to 1 or 2"
INSTL_DATABASE_ENCRYPTION_VERIFY_SERVER_CERT_LABEL_SHORT="Verify SSL certificate for database connection. Values: 0=No, 1=Yes. Requires encryption to be set to 1 or 2"
INSTL_DATABASE_HOST_DESC="Database host"
INSTL_DATABASE_HOST_DESC_SHORT="Database host"
INSTL_DATABASE_NAME_DESC="Database name"
INSTL_DATABASE_NAME_DESC_SHORT="Database name"
INSTL_DATABASE_PASSWORD_DESC="Database password"
INSTL_DATABASE_PASSWORD_DESC_SHORT="Database password"
INSTL_DATABASE_PREFIX_DESC="Prefix for the database tables"
INSTL_DATABASE_PREFIX_DESC_SHORT="Prefix for the database tables"
INSTL_DATABASE_TYPE_DESC="Database type. Supported: mysql, mysqli, pgsql"
INSTL_DATABASE_TYPE_DESC_SHORT="Database type. Supported by Joomla: mysql (=MySQL (PDO)), mysqli (=MySQLi), pgsql (=PostgreSQL (PDO))"
INSTL_DATABASE_USER_DESC="Database username"
INSTL_DATABASE_USER_DESC_SHORT="Database username"
INSTL_SITE_NAME_DESC="Enter the name of your Joomla site"
INSTL_SITE_NAME_DESC_SHORT="Name of the website"
Loading

0 comments on commit f340734

Please sign in to comment.