J4.x

Mise à jour CLI (lignes de commande)

From Joomla! Documentation

Revision as of 11:43, 19 October 2019 by Cavo789 (talk | contribs) (Created page with "====Commandes des composants====")
GSoC 2018
Documentation
sur les lignes de commande
Joomla! 
4.x

Introduction

Pour effectuer une tâche mineure dans Joomla!, le tableau de bord de l'administrateur peut sembler fastidieux et lent. La mise à jour de l'application CLI introduit un moyen plus rapide d'effectuer certaines de ces opérations via la ligne de commande. Cela offre un moyen d'intégrer les choses plus rapidement dans l'application Joomla!. Grâce à ce logiciel, les petits tests peuvent être effectués plus rapidement sans passer par le processus du tableau de bord Web. C’est une application CLI pour Joomla! CMS qui permet à l'utilisateur d'effectuer des mises à jour dans le CMS.

Cette documentation montre comment utiliser la mise à jour de l'application CLI et comment étendre ses fonctionnalités en tant que développeur.

Pré-requis

Comme c'est le cas pour toutes les applications CLI (Command Line Interface), l'accès à votre installation Joomla! via la ligne de commande est nécessaire pour utiliser les outils fournis par le CLI Update. Vous devriez peut-être envisager d'avoir un accès SSH pour votre serveur en direct.


Termes et définitions

  • CLI - Command Line Interface
  • SSH - Secure SHell

Utilisation de la mise-à-jour en mode CLI

In other for you to use the tools provided by CLI Update, as said in former section, you need access to a CLI into the root of the Joomla Installation. In other words you have to be in the root folder of your Joomla CMS as all commands will run from the root folder.

Utilisation des commandes générales

Dans cette section, nous parlerons de l'utilisation des commandes, nous parlerons des différentes commandes, de ce qu'elles sont et comment vous pouvez les utiliser. Nous irons voir les commandes disponibles dans la mise à jour de CLI.

Commandes disponibles

Il y a un certain nombre de commandes disponibles dans la mise à jour de CLI qui sont prêtes à l'emploi. Ces commandes sont regroupées en fonction de la zone du CMS Joomla ! qu'elles touchent.

Vérification des mises à jour mises à jour

La mise à jour de CLI fournit une commande pour vérifier les mises à jour de Joomla!, elle fonctionne comme la version web de com_joomlaupdate, elle récupère la mise à jour et indique si la mise à jour est disponible ou pas. Pour lancer la vérification de mise à jour, nous allons simplement lancer la commande comme ceci à partir du répertoire racine :
php cli/joomla.php check-updates
La commande s'exécute et la sortie affiche une version de mise à jour disponible, si disponible, ou indique que l'installation actuelle est à jour.

Commandes des composants

The next group of commands are the extension based commands, simply put, the commands allows us to manage extensions within the Jommla! core, the CLI Update ships with commands to install, list and remove extensions.

Listing installed extensions

This command allows us to list all installed extensions. This command can run in two different ways which are:

  • General Listing: Lists all the extensions installed, by extensions it means components, languages, plugins, modules will be listed together when you run this command. This is how you call the command:
    php cli/joomla.php extension:list
  • Listing By types: General listing of extension can be tedious if you're looking for a particular extension out of the big list, however, you can beat down the numbers specifying the type of extensions you can the command to display by adding a type option to the command. Here is how that is done:
    php cli/joomla.php extension:list --type=language

This will list out only language based extensions, you can specify type as module, plugin and component as well.

Installing an Extension

Joomla provides installing an extension through an URL to the zip file or a path to the file, the CLI Update provides both as well and how you can use them is described below.

  • Installing from a PATH:To install an extension from a PATH we will run the same extension:install command and specify arguments for paths like this:
    php cli/joomla.php extension:install path --path=/Users/bosunski/docs/com_pathtester.zip

This loads the extension and performs the installation as expected.

Removing an extension

The last command under this category is the extension:remove command that is used to remove extensions from the Joomla CMS. This command takes in the extension_id as an argument, you can always use the extension:list to display extension id. This is how we remove an extension of id 803
php cli/joomla.php extension:remove 803

Updating the Joomla Core

As much as the CLI Update provides a command to check update, it also provides a command to perform the update if an update is available. To perform update we will just run this:
php cli/joomla.php core:update
This command updates the Joomla core updating it to the latest version available.

Installing Joomla! via the CLI

The next command here is the core:install command that lets installation of Joomla CMS to be done via the CLI. This command can work in 2 modes: The Interactive mode and the Non-interactive mode.

Interactive installation

To have a fresh installation of Joomla using the interactive mode we will just run the extension:install command like so:
php cli/joomla.php extension:install

The default installation mode will run and will ask you to input the settings as it's required, once all options have been provided and validated, the installations will run and Joomla will be installed.

Non-interactive Installation

The next type of installation is the Non-interactive mode. In this mode you will not be asked to input the options but rather all options will be specified within a file and the command will take in an option that specifies the path to the file you want to load the options from, it's done like this:
php cli/joomla.php core:install --file=/path/to/config.json

An example of the contents of config.json can be:

{
  "language":"en-GB",
  "site_name":"Joomla",
  "admin_email":"email@example.com",
  "admin_user":"user",
  "admin_password":"password",
  "db_type":"mysql",
  "db_host":"localhost",
  "db_user":"root",
  "db_pass":"xcdxcx",
  "db_name":"jtest",
  "db_prefix":"efs0k_",
  "db_old":"remove",
  "helpurl":"https://joomla.org"
}

OR as sample config.ini

site_name="gsoc"
admin_email="user@example.com"
admin_user="user"
admin_password="secret"
db_type="mysql"
db_host="localhost"
db_user="root"
db_pass=""
db_name="joomla"
db_prefix="prefix_"

The options defined are loaded and validated after which the installation will run.


Configuration based commands

The next set of commands we will be looking at is for setting and viewing configuration options inside the Joomla installation:

Setting configurations

The CLI Update provides a command to change the value of an option existing in the configuration. Using the config:get command you can set any configuration option that exists inside the configuration.php. This is how to use command:
php cli/joomla.php config:set mailer=mail

You can even add multiple option-value pairs like this:
php cli/joomla.php config:set mailer=mail fromname=Joomla! sitename="Joomla Site" This will set multiple options at once.

Getting configurations

The next command in this category is the config:get command, as the name suggests it gets the value of an option that exists inside the configuration.php, when no argument is supplied to the command, it will display all the options available in a tabulated form. Here is the command:
php cli/joomla.php config:get sitename

This will return the value for the option sitename.

php cli/joomla.php config:get

This will return all the values for the available options.

Getting grouped configurations

The CLI Update adds an option to config:get command that allows us to get logically grouped options, say for example you want to view all your database related options, or you want to view all email related options. To achieve this the CLI Update provides an option to specify a group of options to display, here is how to do that:

php cli/joomla.php config:get --group=mail

The command takes in the group option and given the value of mail. CLI Update currently supports group values: mail, db and session.

Site down and Site up commands

As their name suggests, these commands allow you to quickly put your Joomla powered website into offline or online mode. Here is how to use the commands:
php cli/joomla.php site:up

php cli/joomla.php site:down

The second command puts the website in offline mode while the first command brings the website to online mode.


Contributing to CLI Update as a developer

Adding more commands

The CLI Update ships with some commands which are added based on the need seen as of the time. However, the CLI Update allows other commands to be added easily and this is what this section is for. A video tutorial is included below.

Calling other commands within command classes

Should in case a command you want to write for the CLI Update is going to be require that you call an existing command internally, this is how that can be achieved from within another command class:

<?php
class RunHelloCommand extends AbstractCommand {
    ...

    public function execute(): int {
        $command = $this->getApplication()->getCommand('say:hello');
        $code = $command->execute();

        if($code === 0) {
            // command ran successfully, do something
        }
    }

    ...
}

Here, we're attempting to call the say:hello command created in the Video above.

Some important things to checkout