「コマンドラインによる管理」の版間の差分

提供:MoodleDocs
移動先:案内検索
(done.)
編集の要約なし
(2人の利用者による、間の44版が非表示)
1行目: 1行目:
あなたのウェブサーバにシェルアクセスできる場合、Moodle管理に有用な様々なCLI (command line interface コマンドライン・インターフェース) を見つけることができるでしょう。すべてのコマンドラインツールは「<code>admin/cli/*</code>」ディレクトリ内にあります。アクセスコントロールの問題を避けるには、ウェブサーバプロセスのオーナーとして実行してください。CLIによるインストールおよびアップグレード時に新しいファイルをmoodledataディレクトリに作成するため、ウェブサーバにディレクトリへの書き込み権限が与えてあることは特に重要です。Linuxディストリビューションでは、通常ウェブサーバを実行するユーザは「apache」または「wwrun」または「httpd」のようになっています。恐らく、あなたはrootとして次のようにMoodle CLIスクリプトを実行したいことでしょう:
{{Moodleのインストール}}
 
再作成中です - [[利用者:Mitsuhiro Yoshida|Mitsuhiro Yoshida]] ([[利用者・トーク:Mitsuhiro Yoshida|トーク]])
 
== CLIスクリプトの実行==
Webサーバへのシェルアクセスがある場合、Moodleの管理中にさまざまなCLI(コマンドラインインターフェース)スクリプトが役立つ場合があります。コア管理CLIツールは<code>admin/cli/*</code>フォルダにあります。他のプラグインは、独自のcliフォルダ内のスクリプトを介してCLI機能を提供します。たとえば、enrol_db同期スクリプトは<code>enrol/db/cli/</code>にあります。
 
アクセス制御の問題を回避するには、Webサーバプロセスの所有者としてそれらを実行する必要があります。 CLIのインストールとアップグレードでは、moodledataディレクトリに新しいファイルが作成され、Webサーバがそれらに書き込みアクセスできる必要があるため、特に重要です。 Linuxディストリビューションでは、Webサーバを実行するユーザは通常、apache、wwrun、httpdなどです。ルートとして、あなたはおそらく次のようなMoodleCLIスクリプトを実行したいと思うでしょう:


     $ cd /path/to/your/moodle/dir
     $ cd /path/to/your/moodle/dir
     $ sudo -u apache /usr/bin/php admin/cli/somescript.php --params
     $ sudo -u apache /usr/bin/php admin/cli/somescript.php --params


使用方法の詳細説明を表示するため、ほとんどのスクリプトでは一般的な --help (または -h) パラメータを使うことができます。例えば下記のように使います:
ほとんどのスクリプトは、共通の--help(または-h)パラメータを受け入れて、完全な使用法情報を表示します。次に例を示します。


     $ sudo -u apache /usr/bin/php admin/cli/install.php --help
     $ sudo -u apache /usr/bin/php admin/cli/install.php --help


{{Note|これらのスクリプトは、WebサーバユーザのIDで実行されることになっています。このページの例では、説明のためにapacheユーザを使用しています。特定の値は、OSのディストリビューションとローカルセットアップによって異なります。一般的な値は、 <tt>apache</tt> 、 <tt>www-data</tt>、または<tt>httpd</tt>です。}}


== コマンドライン経由のインストール ==
==アップグレード==
Moodleはコマンドラインからアップグレードできます。インストールスクリプトと同様に、アップグレードには対話型モードまたは非対話型モードのいずれかがあります。スクリプト自体はサイトをメンテナンスモードにしません。自分で行う必要があります。また、スクリプトはデータをバックアップしません(このページを読んだ場合、おそらくmoodledataとデータベースをバックアップするための独自のスクリプトがいくつかありますよね?)
 
    $ sudo -u apache /usr/bin/php admin/cli/upgrade.php
 
MoodleソースコードのGitチェックアウトを使用する場合、コマンドラインからのアップグレードはMoodleアップグレードの非常に快適な方法です([[管理者用Git]]を参照)。 gitリポジトリで追跡された最終的なローカルカスタマイズを保持しながら、数秒以内にサイトを最新バージョンにアップグレードする方法については、次の手順を参照してください。
 
    $ cd /var/www/sites/moodle/htdocs/
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable
    $ git pull
    $ sudo -u apache /usr/bin/php admin/cli/upgrade.php
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable


バージョン2.0以降、Moodleではコマンドラインを使ってインストールすることができます。インストールには2つのモードがあります。インタラクティブモードでは、インストールスクリプトが新しいMoodleサイトをセットアップするために必要なデータすべてに関して、あなたに尋ねます。非インタラクティブモードでは、あなたはスクリプトパラメータとして、すべての必須データを提供することにより、新しいサイトが静かにインストールされます。インタラクティブモードでもパラメータを渡すことができます。渡された値はインタラクティブセッション中、デフォルト値として使用されます。
==インストール==
コマンドラインからMoodleをインストールする方法は2つあります。インタラクティブモードでは、インストールスクリプトは新しいMoodleサイトを適切にセットアップするために必要なすべてのデータを要求します。非対話型モードでは、必要なすべてのデータをスクリプトパラメータとして指定する必要があります。そうすると、新しいサイトがサイレントインストールされます。パラメータは、インタラクティブモードでも渡すことができます。提供された値は、対話型セッション中にデフォルト値として使用されます。


     $ sudo -u apache /usr/bin/php admin/cli/install.php --lang=cs
     $ sudo -u apache /usr/bin/php admin/cli/install.php --lang=cs


== メンテナンスモード ==
必要に応じて、config.phpを入力するだけで、データベースのインストールをスキップできます。


あなたのサイトをCLI経由でメンテナンスモードにスイッチするには、下記コマンドを実行してください。
  $ sudo -u apache /usr/bin/php admin/cli/install.php --skip-database
 
==メンテナンスモード==
CLIを介してサイトをメンテナンスモードに切り替えるには、次を使用できます。


     $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable
     $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable


メンテナンスモードをOFFにするには、同様のスクリプトを --disable parameter オプションを付けて実行してください。
メンテナンスモードをオフにするには、-disableパラメータを指定して同じスクリプトを実行します。


== オフラインモード ==
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable


場合によってはウェブ経由でアクセスできないよう、あなたのMoodleサイトをオフラインモードにスイッチしたいこともあるでしょう。しかし、ウェブサーバを完全に停止することはできません (一般的に他のページが存在しているか、他のアプリケーションが動作しているからです)。moodledataディレクトリのルートフォルダ内に「<code>climaintenance.html</code>」というファイル名のファイルが存在する場合、Moodleはこのファイルのコンテンツを他のページの代わりに表示します。
メンテナンスモードをすぐに有効にしたくないが、ユーザにカウントダウンを表示する場合は、-enablelaterパラメータとカウントダウンを実行する分数を指定して同じスクリプトを実行します。
 
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enablelater=10
 
このスクリプトは、''オフライン'' モードのclimaintenance.htmlファイルも作成および削除します。
 
==オフラインモード==
状況によっては、Moodleサイトをオフラインモードに切り替えて、Web経由でアクセスできないようにしたい場合がありますが、Webサーバを完全に停止することはできません(通常、他のWebページやアプリケーションが実行されているため)。 <code>climaintenance.html</code>というファイルがmoodledataディレクトリのルートフォルダに存在する場合、Moodleは他のページの代わりにそのファイルの内容を自動的に表示します。


     $ cd /var/www/sites/moodle/moodledata/
     $ cd /var/www/sites/moodle/moodledata/
     $ echo '&lt;h1&gt;Sorry, maintenance in progress&lt;/h1&gt;' &gt; climaintenance.html
     $ echo '&lt;h1&gt;Sorry, maintenance in progress&lt;/h1&gt;' &gt; climaintenance.html


あなたのユーザにサーバ停止を知らせるため、moodledataディレクトリ内にHTMLフォーマットで作成した<code>climaintenance.off</code>のような名称のファイルを準備することができるでしょう。そして、必要に応じて、そのファイルを<code>climaintenance.html</code>にリネームすることができます。
あなたは停止しているサーバについてユーザに通知するための適切な形式のHTMLページを準備し、moodledataディレクトリに<code>climaintenance.off</code>のような名前で保持し、必要に応じて名前を<code>climaintenance.html</code>に変更できます。
 
==カスタムサイトのデフォルト==
CLIを介したインストールおよびアップグレード中にMoodleは管理変数をデフォルト値に設定します。さまざまなデフォルトを使用できます。詳細についてはMDL-17850を参照してください。間もなく、あなたがする必要があるのはファイル<code>local/defaults.php</code>をMoodleインストールに追加することです。ファイルのフォーマットは以下のようになります:
 
<code php>
<?php
$defaults['pluginname']['settingname'] = 'settingvalue'; // for plugins
$defaults['moodle']['settingname'] = 'settingvalue';    // for core settings
</code>
 
これらのデフォルトはインストール、アップグレード中に使用され、サイト管理ページにもデフォルトとして表示されます。
 
==ユーザパスワードをリセットする==
管理者パスワードを忘れた場合(またはサイト上の他のユーザのパスワードを設定したい場合)はreset_password.phpスクリプトを使用できます。スクリプトは指定されたユーザに正しくソルトされたパスワードを設定します。
 
    $ sudo -u apache /usr/bin/php admin/cli/reset_password.php
 
==InnoDBからBarracudaに変換する==
MySQLおよびMariaDBの新しいバージョンにはBarracudaと呼ばれる改良されたファイルフォーマットがあります。これを利用するには:
# あなたのMySQL/MariaDBのバージョンがラージインデックスキープレフィックス(innodb_large_prefix)でBarracudaを使用していることを確認してください。詳細は以下をご覧ください。
# Change to the compressed row format (see [[#Changing_tables_to_compressed_row_format|Changing tables to compressed row format]])
# 圧縮行フォーマットに変更してください (詳細は [[#テーブルを圧縮行フォーマットに変更する]]をご覧ください)。
# Change the character set and collation for full Unicode support (see [[#Converting_character_set_and_collation|Converting character set and collation]]).
# Unicodeを完全にサポートするために文字セットおよび照合順序を変更してください 詳細は ( [[#文字セットおよび照合順序を変換する]]をご覧ください)。
 
 
あなたがMySQL 8.0.0以降、またはMariaDB 10.3.0以降を使用している場合、これらのバージョンはラージインデックスキープレフィックスのBarracudaのみをサポートしています。それ以前のバージョンでMySQL/MariaDBがBarracudaを使用しているか確認するには、MySQL/MariaDBクライアントまたはphpMyAdmin SQLタブで以下のステートメントを実行してください:
If you have MySQL 8.0.0 or later, or MariaDB 10.3.0 or later, then these versions only support Barracuda with the large index key prefix. For earlier versions to check if MySQL/MariaDB is using Barracuda run the following statement in the MySQL/MariaDB client or phpMyAdmin SQL tab:
SHOW GLOBAL VARIABLES WHERE variable_name IN ('innodb_file_format', 'innodb_large_prefix', 'innodb_file_per_table');
あなたの設定が以下の表のいずれにも一致しない場合、[[MySQL#フルUTF-8サポートを設定する]]を参考に設定を変更してください:
If your settings do not match any of the tables below, see [[MySQL#Configure_full_UTF-8_support|Configure full UTF-8 support]] for how to change these settings:


== コマンドラインを使ったアップグレード ==
[[File:phpMyAdmin1.png|alt=innodb_file_format=Barracuda;innodb_file_per_table=ON;innodb_large_prefix=ON]] or [[File:phpMyAdmin2.png|alt=innodb_file_format=(blank);innodb_file_per_table=ON;innodb_large_prefix=(blank)]] or [[File:phpMyAdmin3.png|alt=innodb_file_per_table=ON]]


コマンドラインからMoodleをアップグレードすることもできます。インストールスクリプトと同じように、アップグレードにはインタラクティブおよび非インタラクティブモードがあります。スクリプト自体はサイトをメンテナンスモードにしないため、あなた自身でスイッチする必要があります。また、このスクリプトはデータをバックアップしません (恐らく、このドキュメントを読んでいるあなたはmoodledataおよびデータベースをバックアップする独自スクリプトをお持ちですよね?)
If your settings match one of these tables then MySQL/MariaDB is using Barracuda with the large index key prefix.
あなたの設定がこれらのテーブルに一致する場合、MySQL/MariaDBはラージインデックスキープレフィックスでBarracudaを使用しています。
===テーブルを圧縮行フォーマットに変更する===
このスクリプトは多数のテキスト列を持つテーブルでROW_FORMAT=COMPRESSEDを使用するように変更します。This script changes tables with many text columns to use ROW_FORMAT=COMPRESSED. This change isn’t required but is recommended. If the database error ''Row size too large (> 8126)'' occurs when using Moodle then run this script to fix this. この変更は必須ではありませんが推奨します。もし、Moodleを使用中にデータベースエラー ''Row size too large (> 8126)'' が発生した場合、このスクリプトを実行して修正してください。


    $ sudo -u apache /usr/bin/php admin/cli/upgrade.php --non-interactive
'''Note:''' If you have MariaDB version 10.6.0 to 10.6.6 or version 10.7.0 to 10.7.2 you must upgrade to a later version before running this script. See MDL-72131 for details.
'''注意:'' MariaDBバージョン10.6.0から10.6.6、またはバージョン10.7.0から10.7.2を使用している場合、このスクリプトを実行する前にそれ以降のバージョンにアップグレードする必要があります。詳細はMDL-72131をご覧ください。


あなたがMoodleコードの取得に[[管理者用CVS|CVS]]または[[Git|git]]を使用している場合、コマンドライン経由でのアップグレードは非常に快適な方法です。以下の手順では、最終的なローカルのカスタマイズを保持したままgitリポジトリでトラック (追跡 track) して、あなたのサイトを数秒で最新バージョンにアップグレードする方法を記します:
To view tables requiring conversion, use the --list option:
変換が必要なテーブルを表示するには「--list」オプションを使用してください。
$ php admin/cli/mysql_compressed_rows.php --list
Here is an example output:
以下、結果出力例です:
mdl_data                            Compact    (needs fixing)
mdl_data_fields                    Compact    (needs fixing)
mdl_enrol_paypal                    Compact    (needs fixing)
To proceed with the conversion, run the command using the fix option:
変換を進めるには以下のように「fix」オプションを使用してコマンドを実行してください:
$ php admin/cli/mysql_compressed_rows.php --fix
Successful table conversion will be reported in the output, for example:
テーブル変換に成功した場合、例えば次のように出力されます:
mdl_data                  ... Compressed
mdl_data_fields            ... Compressed
mdl_enrol_paypal          ... Compressed
If you get errors due to having insufficient privileges to run these commands use --showsql to generate the required SQL commands:
これらのコマンドを実行するのに十分な権限がないためにエラーが発生した場合、--showsqlを使用して必要なSQLコマンドを生成してください:
$ php admin/cli/mysql_compressed_rows.php --showsql
You can then copy the generated SQL into your MySQL/MariaDB client running as the 'root' user.
そして、あなたは生成されたSQLを「root」ユーザとして動作しているMySQL/MariaDBクライアントにコピーできます。
===文字セットおよび照合順序を変換する===
This script changes the Moodle database tables to enable full Unicode support.
このスクリプトはMoodleデータベーステーブルを変更してUnicode完全サポートを有効にします。
$ php admin/cli/mysql_collation.php --collation=utf8mb4_unicode_ci
After making this change edit config.php and change the 'dbcollation' to 'utf8mb4_unicode_ci' in the $CFG->dboptions array.
この変更後、config.phpを編集して$CFG->dboptions配列の「dbcollation」を「utf8mb4_unicode_ci」に変更してください。
 
For further details see: [[MySQL_full_unicode_support|MySQL full unicode support]]
詳細は次をご覧ください: [[MySQLのフルUnicodeサポート]]
== コマンドライン経由でcronを動作させる Running cron via command line ==
In versions 1.x, you could execute admin/cron.php either from command line or via the web. Since Moodle 2.0, only admin/cli/cron.php script can be run via command line.
バージョン1.xでは、あなたはコマンドラインまたはウェブ経由でadmin/cron.phpを実行できました。Moodle 2.0以降、admin/cli/cron.phpスクリプトのみコマンドラインから実行できます。
== スケジュールタスク Scheduled tasks ==
スケジュールタスクはcronスクリプトによって自動的に実行されますが、それぞれのcron反復で実行される特定のタスクはスケジュールされたタスク設定により決定されます。Scheduled tasks are automatically run by the cron script, but the specific tasks which run on each cron iteration are determined by the scheduled tasks configuration. admin/cli/scheduled_task.phpスクリプトの使用でスケジュールタスク設定の上書きおよびスケジュールタスクの即時実行が可能です。It is possible to override the scheduled tasks configuration and run a single scheduled task immediately using the admin/cli/scheduled_task.php script.
 
This script accepts the following arguments:
このスクリプトは以下の引数を受け付けます:
--list - list all the known scheduled tasks. The tasks are listed by the class name used to run the task. This class name is required as the argument to the next option in order to run a specific task immediately.
--list - 既知のスケジュールタスクすべてを一覧表示します。タスクはタスクの実行に使用されるクラス名で一覧表示されます。このクラス名は特定のタスクをすぐに実行するために 次のオプションの引数として必要です。
 
--execute=<task> - スケジュール設定に関係なく、単一のスケジュールタスクを直ちに実行します。--execute=<task> - Runs a single scheduled task immediately - regardless of scheduling settings. これは無効化されたタスクも実行します。This will even run disabled tasks. タスクはクラスタ上であっても、同じタスクの同時実行を防ぐためロックを使用します。Tasks will still use locking to prevent concurrent execution of the same task - even on clusters. <task>引数のフォーマットは上の-listオプションが返すものと同じにする必要があります。The format of the <task> argument must be the same as returned by the --list option above.
 
--disable=<task> - Disables a single scheduled task (New in 4.3 onwards). The format of the <task> argument must be the same as returned by the --list option above.
  --disable=<task> - 単一のスケジュールタスクを無効にします (4.3以降の新機能)。<task>引数のフォーマットは上の--listオプションが返すものと同じにする必要があります。
 
--enable=<task> - Enables a single scheduled task (New in 4.3 onwards). The format of the <task> argument must be the same as returned by the --list option above.
--enable=<task> - 単一のスケジュールタスクを有効にします (4.3以降の新機能)。<<task>引数のフォーマットは上の--listオプションが返すものと同じにする必要があります。
 
--showsql - Shows sql queries before they are execute
 
--showdebugging - Shows developer debugging info
'''Note:''' You must escape the "\" with an extra \ when using the --execute command. Take the following for example:
<pre>php admin/cli/scheduled_task.php --list</pre>
will return something like:
<pre>
== List of scheduled tasks (http://yourserver.com/moodle) ==
\enrol_imsenterprise\task\cron_task                10 * * * * *      ASAP
\logstore_legacy\task\cleanup_task                * 5 * * * *      ASAP
\logstore_standard\task\cleanup_task              * 4 * * * *      Wednesday, November 12, 2014, 4:35 AM
\mod_forum\task\cron_task                          * * * * * *      ASAP
\core\task\automated_backup_task                  50 * * * * *      ASAP
 
...
</pre>
To run the first task in that list, you would execute
php admin/cli/scheduled_task.php --execute='\enrol_imsenterprise\task\cron_task'
Be aware of the single quotes. Without them, you would need to use double backlashes to avoid escaping by the shell.
=== Ad hoc tasks ===
[[Cron#Low_latency_adhoc_tasks|Ad hoc tasks]] are low-latency tasks that are normally run by the cron. You can run just the queued ad hoc tasks with admin/cli/adhoc_task.php.
 
This script accepts the following options and arguments:
<pre>
-h, --help                Print out this help
    --showsql            Show sql queries before they are executed
    --showdebugging      Show developer level debugging information
-e, --execute            Run all queued adhoc tasks
-k, --keep-alive=N        Keep this script alive for N seconds and poll for new adhoc tasks
-i  --ignorelimits        Ignore task_adhoc_concurrency_limit and task_adhoc_max_runtime limits
-f, --force              Run even if cron is disabled
</pre>
For example to run the currently queued ad hoc tasks:
sudo -u apache php admin/cli/adhoc_task.php -e
 
See also the improvements to ad hoc tasks in [[Scheduled_tasks#Ad_hoc_tasks]]
 
==Database transfer==
A command line script for [[Database transfer]] may be found in ''admin/tool/dbtransfer/cli/migrate.php''.
==Purge caches==
You can purge caches using this script:
  php admin/cli/purge_caches.php
==Kill all sessions==
If needed for administrative reasons, you can kill all user sessions using this script:
php admin/cli/kill_all_sessions.php
As a result, all users will be logged out from Moodle.
==Backup and restore of large courses==
See Backup via CLI in [[Course backup]] and Restore via CLI in [[Course restore]] (new in 3.10 onwards).
==Fix course / module sequences==
In rare cases (such as after upgrading from a very old version of Moodle), the course / section / module sequence data can be out of sync. This can cause various problems for affected courses, such as sections not appearing, backups failing, pages not displaying etc. There is a specific check to check for errors caused by this problem, and to fix the data in the database if they are found. To run this script please use the command below:
  php admin/cli/fix_course_sequence.php -c=* --fix
This will check every course in Moodle and report which ones had errors and were fixed.
==Fix orphaned question categories==
When a quiz is created, a new question category for the quiz is automatically created. In versions of Moodle prior to 2.9.1, if the quiz is deleted, the question category and any questions in the category remain in database. These orphaned question categories may be fixed by running the admin/cli/fix_orphaned_question_categories.php script with the --fix option.
==Search and replace text==
This script can be used to search and replace text throughout the whole database. Use carefully and backup first always. More info in [[Search and replace tool]].
  php admin/tool/replace/cli/replace.php --search=//oldsitehost --replace=//newsitehost
==Build theme CSS cache==
If Moodle is not running in theme designer mode it will keep a copy of the compiled CSS on local disk and serve that to the browser when it requests a page. If there isn't a copy on local disk then a copy will be built the first time a page within Moodle is requested.
 
With this script you can pre-compile the cached CSS files for themes within Moodle to avoid having a user wait for the theme to compile during the first page request.
  php admin/cli/build_theme_css.php --themes=boost
==Get and set configuration values==
Displays the current value of the given setting, or set the given setting to the specified value.
$ php admin/cli/cfg.php [--component=<componentname>] [--json] [--shell-arg]
$ php admin/cli/cfg.php --name=<configname> [--component=<componentname>] [--shell-arg] [--no-eol]
$ php admin/cli/cfg.php --name=<configname> [--component=<componentname>] --set=<value>
$ php admin/cli/cfg.php --name=<configname> [--component=<componentname>] --unset
$ php admin/cli/cfg.php [--help|-h]
Examples:
$ php admin/cli/cfg.php --name=langmenu
will display the value of ''Display language menu'' in ''Site administration > Language > Language settings'' (0 for ''No'' or 1 for ''Yes'').
$ php cfg.php --name=maxsizetodownload --component=folder
will display the value of ''Maximum folder download size (MB)'' accessible from ''Site administration > Plugins > Activity modules > Folder''.
$ php admin/cli/cfg.php --name=langmenu --set=0
will disable the ''Language menu''.
==E-mail flag for users==
'''New in 4.2'''
The CLI script to change the email flag for one or many users at a time can be found on the page [[E-Mail flag for users]]
 
== Dashboard reset ==
If you make changes to the dashboard and want all users to have their dashboard reset to reflect the changes this can be done on the cli:
php admin/cli/dashboard_reset.php -e
 
== Managing plugins via command line ==
=== List and uninstall Moodle plugins ===
Moodle includes a handy command-line tool to display a list of plugins and remove plugins.
$ php admin/cli/uninstall_plugins.php
This command line tool accepts the following arguments.
 
Options:
    -h --help                   Print this help.
    --show-all                  Displays a list of all installed plugins.
    --show-contrib              Displays a list of all third-party installed plugins.
    --show-missing              Displays a list of plugins missing from disk.
    --purge-missing             Uninstall all missing from disk plugins.
    --plugins=<plugin name>     A comma separated list of plugins to be uninstalled. E.g. mod_assign,mod_forum
    --run                       Execute uninstall. If this option is not set, then the script will be run in a dry mode.
    --showsql                   Show sql queries before they are executed.
    --showdebugging             Show developer level debugging information.
Dry Mode does everything the script would normally do except for actually making any changes. This is useful when you want to test the validity of your command.
 
Run this command from the Moodle wwwroot directory. Here are some examples:
    # php admin/cli/uninstall_plugins.php  --show-all
        Prints tab-separated list of all installed plugins.
    # php admin/cli/uninstall_plugins.php  --show-contrib
        Prints tab-separated list of all third-party installed plugins.
    # php admin/cli/uninstall_plugins.php  --show-missing
<blockquote>        Prints tab-separated list of all missing from disk plugins.</blockquote>
    # php admin/cli/uninstall_plugins.php  --purge-missing
        A dry run of uninstalling all missing plugins. This will NOT uninstall the plugin. To actually uninstall, you need to add the '--run' arguments.
    # php admin/cli/uninstall_plugins.php  --purge-missing --run
        Run uninstall of all missing plugins.
    # php admin/cli/uninstall_plugins.php  --plugins=mod_assign,mod_forum
        A dry run of uninstalling mod_assign and mod_forum plugins. This will NOT uninstall the plugin. To actually uninstall, you need to add the '--run' arguments.
    # php admin/cli/uninstall_plugins.php  --plugins=mod_assign,mod_forum --run
        Run uninstall for mod_assign and mod_forum plugins.
 
This tool does not perform all of the steps needed to fully uninstall a plugin. You must then:
* Remove the files belonging to the plugin manually;
* [[Administration via command line#Upgrading|Update the Moodle database]] as previously described.
If you skip one or both of these steps, you will be prompted to update the Moodle database or re-install the plugin the next time you log in as a site administrator and access the Site Administration > Notifications page.
 
■■■■■■■■■■■■■■■■■■■■■■■■■■■■
 
== CLIスクリプトの実行==
Webサーバへのシェルアクセスがある場合、Moodleの管理中にさまざまなCLI(コマンドラインインターフェース)スクリプトが役立つ場合があります。コア管理CLIツールは<code>admin/cli/*</code>フォルダにあります。他のプラグインは、独自のcliフォルダ内のスクリプトを介してCLI機能を提供します。たとえば、enrol_db同期スクリプトは<code>enrol/db/cli/</code>にあります。
 
アクセス制御の問題を回避するには、Webサーバプロセスの所有者としてそれらを実行する必要があります。 CLIのインストールとアップグレードでは、moodledataディレクトリに新しいファイルが作成され、Webサーバがそれらに書き込みアクセスできる必要があるため、特に重要です。 Linuxディストリビューションでは、Webサーバを実行するユーザは通常、apache、wwrun、httpdなどです。ルートとして、あなたはおそらく次のようなMoodleCLIスクリプトを実行したいと思うでしょう:
 
    $ cd /path/to/your/moodle/dir
    $ sudo -u apache /usr/bin/php admin/cli/somescript.php --params
 
ほとんどのスクリプトは、共通の--help(または-h)パラメータを受け入れて、完全な使用法情報を表示します。次に例を示します。
 
    $ sudo -u apache /usr/bin/php admin/cli/install.php --help
 
{{Note|これらのスクリプトは、WebサーバユーザのIDで実行されることになっています。このページの例では、説明のためにapacheユーザを使用しています。特定の値は、OSのディストリビューションとローカルセットアップによって異なります。一般的な値は、 <tt>apache</tt> 、 <tt>www-data</tt>、または<tt>httpd</tt>です。}}
 
==アップグレード==
 
Moodleはコマンドラインからアップグレードできます。インストールスクリプトと同様に、アップグレードには対話型モードまたは非対話型モードのいずれかがあります。スクリプト自体はサイトをメンテナンスモードにしません。自分で行う必要があります。また、スクリプトはデータをバックアップしません(このページを読んだ場合、おそらくmoodledataとデータベースをバックアップするための独自のスクリプトがいくつかありますよね?)
 
    $ sudo -u apache /usr/bin/php admin/cli/upgrade.php
 
MoodleソースコードのGitチェックアウトを使用する場合、コマンドラインからのアップグレードはMoodleアップグレードの非常に快適な方法です([[管理者用Git]]を参照)。 gitリポジトリで追跡された最終的なローカルカスタマイズを保持しながら、数秒以内にサイトを最新バージョンにアップグレードする方法については、次の手順を参照してください。


     $ cd /var/www/sites/moodle/htdocs/
     $ cd /var/www/sites/moodle/htdocs/
    $ git fetch
     $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable
     $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable
     $ git merge origin/cvshead
     $ git pull
     $ sudo -u apache /usr/bin/php admin/cli/upgrade.php
     $ sudo -u apache /usr/bin/php admin/cli/upgrade.php
     $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable
     $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable


===コマンドライン経由でのアップグレードの問題===
==インストール==
 
コマンドラインからMoodleをインストールする方法は2つあります。インタラクティブモードでは、インストールスクリプトは新しいMoodleサイトを適切にセットアップするために必要なすべてのデータを要求します。非対話型モードでは、必要なすべてのデータをスクリプトパラメータとして指定する必要があります。そうすると、新しいサイトがサイレントインストールされます。パラメータは、インタラクティブモードでも渡すことができます。提供された値は、対話型セッション中にデフォルト値として使用されます。
 
    $ sudo -u apache /usr/bin/php admin/cli/install.php --lang=cs
 
必要に応じて、config.phpを入力するだけで、データベースのインストールをスキップできます。
 
  $ sudo -u apache /usr/bin/php admin/cli/install.php --skip-database
 
==メンテナンスモード==
 
CLIを介してサイトをメンテナンスモードに切り替えるには、次を使用できます。
 
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable
 
メンテナンスモードをオフにするには、-disableパラメータを指定して同じスクリプトを実行します。
 
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable
 
メンテナンスモードをすぐに有効にしたくないが、ユーザにカウントダウンを表示する場合は、-enablelaterパラメータとカウントダウンを実行する分数を指定して同じスクリプトを実行します。


あなたのconfig.phpが複数のMoodleインスタンスの情報を含んでいる場合 (同じコードを共有している異なるMoodleウェブサイトおよびデータベース)、このスクリプトは静かに実行失敗となります。
    $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enablelater=10


解決用法は、あなたがアップグレードしたいインスタンス以外、すべてのインスタンスをconfig.phpから一時的に取り除くことです。
このスクリプトは、''オフライン'' モードのclimaintenance.htmlファイルも作成および削除します。


これが他のインスタンス (実運用サイト) の問題である場合、config.phpのコピー (1つのMoodleインスタンスのみ含むよう編集したconfig.php) を指すよう、cliスクリプトを修正してください。
==オフラインモード==


== カスタムサイトデフォルト ==
状況によっては、Moodleサイトをオフラインモードに切り替えて、Web経由でアクセスできないようにしたい場合がありますが、Webサーバを完全に停止することはできません(通常、他のWebページやアプリケーションが実行されているため)。 <code>climaintenance.html</code>というファイルがmoodledataディレクトリのルートフォルダに存在する場合、Moodleは他のページの代わりにそのファイルの内容を自動的に表示します。


CLI経由でのインストールおよびアップグレード中、Moodleは管理変数をデフォルトに設定します。あなたは異なるデフォルト値を使用することができます。詳細は、 MDL-17850をご覧ください。手短に言えば、あなたがやるべきことは<code>local/defaults.php</code>ファイルをインストール済みMoodleのディレクトリに入れることです。ファイルのフォーマットは下記のようになります:
    $ cd /var/www/sites/moodle/moodledata/
    $ echo '&lt;h1&gt;Sorry, maintenance in progress&lt;/h1&gt;' &gt; climaintenance.html
 
あなたはダウンしているサーバについてユーザに通知するための適切な形式のHTMLページを準備し、moodledataディレクトリに<code>climaintenance.off</code>のような名前で保持し、必要に応じて名前を<code>climaintenance.html</code>に変更できます。
 
==カスタムサイトのデフォルト==
 
CLIを介したインストールおよびアップグレード中に、Moodleは管理変数をデフォルト値に設定します。さまざまなデフォルトを使用できます。詳細については、MDL-17850を参照してください。間もなく、あなたがする必要があるのは、ファイル<code>local/defaults.php</code>をMoodleインストールに追加することです。ファイルの形式は次のようになります


<code php>
<code php>
<?php
<?php
$defaults['pluginname']['settingname'] = 'settingvalue'; // プラグイン
$defaults['pluginname']['settingname'] = 'settingvalue'; // for plugins
$defaults['moodle']['settingname'] = 'settingvalue';    // コア設定
$defaults['moodle']['settingname'] = 'settingvalue';    // for core settings
</code>
</code>


デフォルト値はインストールおよびアップグレード中に使用されます。また、サイト管理ページにデフォルト値として表示されます。
これらのデフォルトは、インストール、アップグレード中に使用され、サイト管理ページにもデフォルトとして表示されます。


== ユーザパスワードをリセットする ==
==ユーザパスワードをリセット==


あなたが自分の管理者パスワードを忘れてしまった場合、またはあなたのMoodleサイトのユーザのパスワードを設定したい場合、reset_password.phpスクリプトを使用することができます。指定したユーザに対して、正しくSALTしたパスワードが設定されます。
管理者パスワードを忘れた場合(またはサイト上の他のユーザのパスワードを設定したい場合)は、reset_password.phpスクリプトを使用できます。スクリプトは、指定されたユーザに正しくソルトされたパスワードを設定します。


     $ sudo -u apache /usr/bin/php admin/cli/reset_password.php
     $ sudo -u apache /usr/bin/php admin/cli/reset_password.php


== MySQLストレージエンジンの移管==
== MySQLストレージエンジンの変換==


あなたのMoodleサイトのバックエンドにMySQLデータベースを使用して、テーブルのストレージエンジンにデフォルトのMyISAMを使用している場合、さらに信頼性のあるInnoDBのようなエンジンに移管してください (実際には、PostgreSQLにスイッチした方が良いのですが ;-))。
MySQLデータベースバックエンドでMoodleサイトを実行し、テーブルのストレージエンジンとしてデフォルトのMyISAMを使用する場合は、InnoDBなどのより信頼性の高いエンジンを使用するように変換することをお勧めします(実際には、PostgreSQLに切り替える必要があります;-)とにかく)。


     $ sudo -u apache /usr/bin/php admin/cli/mysql_engine.php --engine=InnoDB
     $ sudo -u apache /usr/bin/php admin/cli/mysql_engine.php --engine=InnoDB


== コマンドライン経由でcronを実行する ==
== InnoDBテーブルをBarracudaに変換する==
 
ファイル形式としてAntelopeを使用するデータベーステーブルでMySQLを使用しているサイトでは、テーブルをBarracudaファイル形式に変換することをお勧めします。
 
これは、ファイル形式としてAntelopeを使用するテーブルは、10を超えるテキスト列を処理できないためです。このファイル形式は、下位互換性の理由から、 ''コンパクト'' および ''冗長'' 行フォーマットのみをサポートします。これにより、コースをリストアするときに大規模なサイトで問題が発生する可能性があります。その場合、次のエラーが表示されます。
 
Row size too large (>8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help.
 
Barracudaは、最新のinnoDBファイル形式です。バラクーダは、''コンパクト'' および''冗長'' 行フォーマットをサポートすることに加えて、 ''圧縮'' および ''動的'' 行フォーマットもサポートします。
 
ただし、すべてのMySQLユーザが影響を受けるわけではないため、テーブルをBarracudaに変換することは推奨されるだけであり、必須ではありません。 (これは、大規模なサイトでのみ問題になる可能性があります。)
 
===テーブルを変換するためのツール===
 
テーブルをBarracudaに変換するためのコマンドラインツールがMoodleに含まれています。
 
変換が必要なテーブルを表示するには、リストオプションを使用します。
 
$ php admin/cli/mysql_compressed_rows.php --list
 
出力例を次に示します。
 
mdl_data                            Compact    (needs fixing)
mdl_data_fields                    Compact    (needs fixing)
mdl_enrol_paypal                    Compact    (needs fixing)
 
変換を続行するには、修正オプションを使用してコマンドを実行します。
 
$ php admin/cli/mysql_compressed_rows.php --fix
 
成功したテーブル変換は、出力で報告されます。次に例を示します。
 
mdl_data                  ... Compressed
mdl_data_fields            ... Compressed
mdl_enrol_paypal          ... Compressed
 
コマンドはmoodleディレクトリで実行する必要があることに注意してください。テーブルが修正されると、警告メッセージは表示されなくなります。
 
InnoDBファイル形式の詳細については、[http://dev.mysql.com/doc/innodb/1.1/en/glossary.html#glos_antelope MySQL InnoDBグロッサリー-Antelope]および[http://dev.mysql.com/doc/innodb/1.1/en/glossary.html#glos_barracuda MySQL InnoDB用語集-バラクーダ]を参照してください。
 
これらのコマンドを実行するための十分なパーミッションがないためにエラーが発生した場合(これは非常に可能性が高いです)、最も簡単な解決策は、を使用して必要なSQLコマンドを生成することです。
 
$ php admin/cli/mysql_compressed_rows.php --showsql
 
次に、生成されたSQLを 'root' ユーザとして実行されているmysqlクライアントにコピーできます。
 
==新しい文字セットと照合順序への変換==
 
$ php admin/cli/mysql_collation.php --collation=utf8mb4_unicode_ci
 
==コマンドラインからcronを実行する==
 
バージョン1.xでは、コマンドラインまたはWeb経由でadmin/cron.phpを実行できました。 Moodle 2.0以降、コマンドラインから実行できるのはadmin/cli/cron.phpスクリプトのみです。
 
==スケジュールされたタスク==
 
スケジュールされたタスクはcronスクリプトによって自動的に実行されますが、各cron反復で実行される特定のタスクは、スケジュールされたタスクの構成によって決定されます。 admin/tool/task/cli/schedule_task.phpスクリプトを使用して、スケジュールされたタスクの構成を上書きし、単一のスケジュールされたタスクをすぐに実行することができます。
 
このスクリプトは、次の引数を受け入れます。
 
--list - list all the known scheduled tasks. The tasks are listed by the class name used to run the task. This class name is required as the argument to the next option in order to run a specific task immediately.
 
--execute=<task> - Runs a single scheduled task immediately - regardless of scheduling settings. This will even run disabled tasks. Tasks will still use locking to prevent concurrent execution of the same task - even on clusters. The format of the <task> argument must be the same as returned by the --list option above.
 
--showsql - Shows sql queries before they are execute
 
--showdebugging - Shows developer debugging info
 
'''注:''' --executeコマンドを使用する場合は、追加の\を使用して "\"をエスケープする必要があります。たとえば、次のようにします。
 
<pre>php admin/tool/task/cli/schedule_task.php --list</pre>
 
次のようなものが返されます:
 
<pre>
== List of scheduled tasks (http://yourserver.com/moodle) ==
\enrol_imsenterprise\task\cron_task                10 * * * * *      ASAP
\logstore_legacy\task\cleanup_task                * 5 * * * *      ASAP
\logstore_standard\task\cleanup_task              * 4 * * * *      Wednesday, November 12, 2014, 4:35 AM
\mod_forum\task\cron_task                          * * * * * *      ASAP
\core\task\automated_backup_task                  50 * * * * *      ASAP
 
...
</pre>
 
そのリストの最初のタスクを実行するには、次を実行します
 
php admin/tool/task/cli/schedule_task.php --execute='\enrol_imsenterprise\task\cron_task'
 
一重引用符に注意してください。それらがないと、シェルによるエスケープを回避するために、二重のバックラッシュを使用する必要があります。
 
==データベース移行==
 
[[データベース移行]]のコマンドラインスクリプトは、''admin/tool/dbtransfer/cli/migrate.php'' です。
 
==キャッシュを削除==
 
次のスクリプトを使用して、キャッシュをパージできます。
 
  php admin/cli/purge_caches.php
 
==すべてのセッションを強制終了します==
管理上の理由で必要な場合は、次のスクリプトを使用してすべてのユーザセッションを強制終了できます。
 
php admin/cli/kill_all_sessions.php
 
その結果、すべてのユーザがMoodleからログアウトされます。
 
==コース/モジュールシーケンスの修正==
 
まれに(非常に古いバージョンのMoodleからアップグレードした後など)、コース/セクション/モジュールのシーケンスデータが同期していない可能性があります。これにより、セクションが表示されない、バックアップが失敗する、ページが表示されないなど、影響を受けるコースにさまざまな問題が発生する可能性があります。この問題によって引き起こされるエラーをチェックし、見つかった場合はデータベース内のデータを修正するための特定のチェックがあります。このスクリプトを実行するには、以下のコマンドを使用してください。
 
  php admin/cli/fix_course_sequence.php -c=* --fix
 
これにより、Moodleのすべてのコースがチェックされ、エラーが発生して修正されたコースが報告されます。
 
==孤立した問題カテゴリを修正==
 
小テストが作成されると、小テストの新しい問題カテゴリが自動的に作成されます。 2.9.1より前のバージョンのMoodleでは、小テストが削除された場合、問題カテゴリとそのカテゴリ内の問題はデータベースに残ります。これらの孤立した問題カテゴリは、-fixオプションを指定してadmin/cli /fix_alone_question_categories.phpスクリプトを実行することで修正できます。
 
==テキストの検索と置換==
 
このスクリプトを使用して、データベース全体のテキストを検索および置換できます。慎重に使用し、常に最初にバックアップしてください。詳細については、[[検索および置換ツール]]をご覧ください。
 
  php admin/tool/replace/cli/replace.php --search=//oldsitehost --replace=//newsitehost
 
==ビルドテーマCSSキャッシュ==
 
Moodleがテーマデザイナーモードで実行されていない場合、コンパイルされたCSSのコピーをローカルディスクに保持し、ページを要求したときにそれをブラウザーに提供します。ローカルディスクにコピーがない場合、Moodle内のページが最初にリクエストされたときにコピーが作成されます。
 
このスクリプトを使用すると、Moodle内のテーマのキャッシュされたCSSファイルを事前にコンパイルして、最初のページのリクエスト中にテーマがコンパイルされるのをユーザが待たないようにすることができます。
 
  php admin/cli/build_theme_css.php --themes=boost
 
==構成値の取得と設定==
 
指定された設定の現在の値を表示するか、指定された設定を指定された値に設定します。
 
例:
 
  php admin/cli/cfg.php [--component=<componentname>] [--json] [--shell-arg]
  php admin/cli/cfg.php --name=<configname> [--component=<componentname>] [--shell-arg] [--no-eol]
  php admin/cli/cfg.php --name=<configname> [--component=<componentname>] --set=<value>
  php admin/cli/cfg.php --name=<configname> [--component=<componentname>] --unset
  php admin/cli/cfg.php [--help|-h]


バージョン1.xにおいて、あなたはadmin/cron.phpをコマンドラインまたはウェブ経由で実行することができていました。Moodle 2.0以降、コマンドライン経由でのみ、admin/cli/cron.phpスクリプトを実行することができます。
==関連項目==


[[Category:インストール]]
* MDL-35736 - コマンドラインからプラグインを管理する
* MDL-36237 - CLIによるリゾートコースリスト
* [http://moosh-online.com/ MOOSH] - MOOdleシェル。これは、最も一般的なMoodleタスクを実行できるようにするコマンドラインツールです。


[[en: Administration_via_command_line]]
[[en:Administration via command line]]
[[fr:Administration en ligne de commande]]
[[de:AdministrationüberKommandozeile]]
[[es:Administraciónporlíneadecomando]]
<!--[[it:Amministrazione via linea di comando]]-->

2024年5月21日 (火) 15:02時点における版


再作成中です - Mitsuhiro Yoshida (トーク)

CLIスクリプトの実行

Webサーバへのシェルアクセスがある場合、Moodleの管理中にさまざまなCLI(コマンドラインインターフェース)スクリプトが役立つ場合があります。コア管理CLIツールはadmin/cli/*フォルダにあります。他のプラグインは、独自のcliフォルダ内のスクリプトを介してCLI機能を提供します。たとえば、enrol_db同期スクリプトはenrol/db/cli/にあります。

アクセス制御の問題を回避するには、Webサーバプロセスの所有者としてそれらを実行する必要があります。 CLIのインストールとアップグレードでは、moodledataディレクトリに新しいファイルが作成され、Webサーバがそれらに書き込みアクセスできる必要があるため、特に重要です。 Linuxディストリビューションでは、Webサーバを実行するユーザは通常、apache、wwrun、httpdなどです。ルートとして、あなたはおそらく次のようなMoodleCLIスクリプトを実行したいと思うでしょう:

   $ cd /path/to/your/moodle/dir
   $ sudo -u apache /usr/bin/php admin/cli/somescript.php --params

ほとんどのスクリプトは、共通の--help(または-h)パラメータを受け入れて、完全な使用法情報を表示します。次に例を示します。

   $ sudo -u apache /usr/bin/php admin/cli/install.php --help
注意: これらのスクリプトは、WebサーバユーザのIDで実行されることになっています。このページの例では、説明のためにapacheユーザを使用しています。特定の値は、OSのディストリビューションとローカルセットアップによって異なります。一般的な値は、 apachewww-data、またはhttpdです。

アップグレード

Moodleはコマンドラインからアップグレードできます。インストールスクリプトと同様に、アップグレードには対話型モードまたは非対話型モードのいずれかがあります。スクリプト自体はサイトをメンテナンスモードにしません。自分で行う必要があります。また、スクリプトはデータをバックアップしません(このページを読んだ場合、おそらくmoodledataとデータベースをバックアップするための独自のスクリプトがいくつかありますよね?)

   $ sudo -u apache /usr/bin/php admin/cli/upgrade.php

MoodleソースコードのGitチェックアウトを使用する場合、コマンドラインからのアップグレードはMoodleアップグレードの非常に快適な方法です(管理者用Gitを参照)。 gitリポジトリで追跡された最終的なローカルカスタマイズを保持しながら、数秒以内にサイトを最新バージョンにアップグレードする方法については、次の手順を参照してください。

   $ cd /var/www/sites/moodle/htdocs/
   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable
   $ git pull
   $ sudo -u apache /usr/bin/php admin/cli/upgrade.php
   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable

インストール

コマンドラインからMoodleをインストールする方法は2つあります。インタラクティブモードでは、インストールスクリプトは新しいMoodleサイトを適切にセットアップするために必要なすべてのデータを要求します。非対話型モードでは、必要なすべてのデータをスクリプトパラメータとして指定する必要があります。そうすると、新しいサイトがサイレントインストールされます。パラメータは、インタラクティブモードでも渡すことができます。提供された値は、対話型セッション中にデフォルト値として使用されます。

   $ sudo -u apache /usr/bin/php admin/cli/install.php --lang=cs

必要に応じて、config.phpを入力するだけで、データベースのインストールをスキップできます。

  $ sudo -u apache /usr/bin/php admin/cli/install.php --skip-database

メンテナンスモード

CLIを介してサイトをメンテナンスモードに切り替えるには、次を使用できます。

   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable

メンテナンスモードをオフにするには、-disableパラメータを指定して同じスクリプトを実行します。

   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable

メンテナンスモードをすぐに有効にしたくないが、ユーザにカウントダウンを表示する場合は、-enablelaterパラメータとカウントダウンを実行する分数を指定して同じスクリプトを実行します。

   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enablelater=10

このスクリプトは、オフライン モードのclimaintenance.htmlファイルも作成および削除します。

オフラインモード

状況によっては、Moodleサイトをオフラインモードに切り替えて、Web経由でアクセスできないようにしたい場合がありますが、Webサーバを完全に停止することはできません(通常、他のWebページやアプリケーションが実行されているため)。 climaintenance.htmlというファイルがmoodledataディレクトリのルートフォルダに存在する場合、Moodleは他のページの代わりにそのファイルの内容を自動的に表示します。

   $ cd /var/www/sites/moodle/moodledata/
   $ echo '<h1>Sorry, maintenance in progress</h1>' > climaintenance.html

あなたは停止しているサーバについてユーザに通知するための適切な形式のHTMLページを準備し、moodledataディレクトリにclimaintenance.offのような名前で保持し、必要に応じて名前をclimaintenance.htmlに変更できます。

カスタムサイトのデフォルト

CLIを介したインストールおよびアップグレード中にMoodleは管理変数をデフォルト値に設定します。さまざまなデフォルトを使用できます。詳細についてはMDL-17850を参照してください。間もなく、あなたがする必要があるのはファイルlocal/defaults.phpをMoodleインストールに追加することです。ファイルのフォーマットは以下のようになります:

<?php $defaults['pluginname']['settingname'] = 'settingvalue'; // for plugins $defaults['moodle']['settingname'] = 'settingvalue'; // for core settings

これらのデフォルトはインストール、アップグレード中に使用され、サイト管理ページにもデフォルトとして表示されます。

ユーザパスワードをリセットする

管理者パスワードを忘れた場合(またはサイト上の他のユーザのパスワードを設定したい場合)はreset_password.phpスクリプトを使用できます。スクリプトは指定されたユーザに正しくソルトされたパスワードを設定します。

   $ sudo -u apache /usr/bin/php admin/cli/reset_password.php

InnoDBからBarracudaに変換する

MySQLおよびMariaDBの新しいバージョンにはBarracudaと呼ばれる改良されたファイルフォーマットがあります。これを利用するには:

  1. あなたのMySQL/MariaDBのバージョンがラージインデックスキープレフィックス(innodb_large_prefix)でBarracudaを使用していることを確認してください。詳細は以下をご覧ください。
  2. Change to the compressed row format (see Changing tables to compressed row format)
  3. 圧縮行フォーマットに変更してください (詳細は #テーブルを圧縮行フォーマットに変更するをご覧ください)。
  4. Change the character set and collation for full Unicode support (see Converting character set and collation).
  5. Unicodeを完全にサポートするために文字セットおよび照合順序を変更してください 詳細は ( #文字セットおよび照合順序を変換するをご覧ください)。


あなたがMySQL 8.0.0以降、またはMariaDB 10.3.0以降を使用している場合、これらのバージョンはラージインデックスキープレフィックスのBarracudaのみをサポートしています。それ以前のバージョンでMySQL/MariaDBがBarracudaを使用しているか確認するには、MySQL/MariaDBクライアントまたはphpMyAdmin SQLタブで以下のステートメントを実行してください: If you have MySQL 8.0.0 or later, or MariaDB 10.3.0 or later, then these versions only support Barracuda with the large index key prefix. For earlier versions to check if MySQL/MariaDB is using Barracuda run the following statement in the MySQL/MariaDB client or phpMyAdmin SQL tab:

SHOW GLOBAL VARIABLES WHERE variable_name IN ('innodb_file_format', 'innodb_large_prefix', 'innodb_file_per_table');

あなたの設定が以下の表のいずれにも一致しない場合、MySQL#フルUTF-8サポートを設定するを参考に設定を変更してください: If your settings do not match any of the tables below, see Configure full UTF-8 support for how to change these settings:

ファイル:phpMyAdmin1.png or ファイル:phpMyAdmin2.png or ファイル:phpMyAdmin3.png

If your settings match one of these tables then MySQL/MariaDB is using Barracuda with the large index key prefix. あなたの設定がこれらのテーブルに一致する場合、MySQL/MariaDBはラージインデックスキープレフィックスでBarracudaを使用しています。

テーブルを圧縮行フォーマットに変更する

このスクリプトは多数のテキスト列を持つテーブルでROW_FORMAT=COMPRESSEDを使用するように変更します。This script changes tables with many text columns to use ROW_FORMAT=COMPRESSED. This change isn’t required but is recommended. If the database error Row size too large (> 8126) occurs when using Moodle then run this script to fix this. この変更は必須ではありませんが推奨します。もし、Moodleを使用中にデータベースエラー Row size too large (> 8126) が発生した場合、このスクリプトを実行して修正してください。

Note: If you have MariaDB version 10.6.0 to 10.6.6 or version 10.7.0 to 10.7.2 you must upgrade to a later version before running this script. See MDL-72131 for details. '注意: MariaDBバージョン10.6.0から10.6.6、またはバージョン10.7.0から10.7.2を使用している場合、このスクリプトを実行する前にそれ以降のバージョンにアップグレードする必要があります。詳細はMDL-72131をご覧ください。

To view tables requiring conversion, use the --list option: 変換が必要なテーブルを表示するには「--list」オプションを使用してください。

$ php admin/cli/mysql_compressed_rows.php --list

Here is an example output: 以下、結果出力例です:

mdl_data                            Compact     (needs fixing) 
mdl_data_fields                     Compact     (needs fixing)
mdl_enrol_paypal                    Compact     (needs fixing)

To proceed with the conversion, run the command using the fix option: 変換を進めるには以下のように「fix」オプションを使用してコマンドを実行してください:

$ php admin/cli/mysql_compressed_rows.php --fix

Successful table conversion will be reported in the output, for example: テーブル変換に成功した場合、例えば次のように出力されます:

mdl_data                   ... Compressed
mdl_data_fields            ... Compressed
mdl_enrol_paypal           ... Compressed

If you get errors due to having insufficient privileges to run these commands use --showsql to generate the required SQL commands: これらのコマンドを実行するのに十分な権限がないためにエラーが発生した場合、--showsqlを使用して必要なSQLコマンドを生成してください:

$ php admin/cli/mysql_compressed_rows.php --showsql

You can then copy the generated SQL into your MySQL/MariaDB client running as the 'root' user. そして、あなたは生成されたSQLを「root」ユーザとして動作しているMySQL/MariaDBクライアントにコピーできます。

文字セットおよび照合順序を変換する

This script changes the Moodle database tables to enable full Unicode support. このスクリプトはMoodleデータベーステーブルを変更してUnicode完全サポートを有効にします。

$ php admin/cli/mysql_collation.php --collation=utf8mb4_unicode_ci

After making this change edit config.php and change the 'dbcollation' to 'utf8mb4_unicode_ci' in the $CFG->dboptions array. この変更後、config.phpを編集して$CFG->dboptions配列の「dbcollation」を「utf8mb4_unicode_ci」に変更してください。

For further details see: MySQL full unicode support 詳細は次をご覧ください: MySQLのフルUnicodeサポート

コマンドライン経由でcronを動作させる Running cron via command line

In versions 1.x, you could execute admin/cron.php either from command line or via the web. Since Moodle 2.0, only admin/cli/cron.php script can be run via command line. バージョン1.xでは、あなたはコマンドラインまたはウェブ経由でadmin/cron.phpを実行できました。Moodle 2.0以降、admin/cli/cron.phpスクリプトのみコマンドラインから実行できます。

スケジュールタスク Scheduled tasks

スケジュールタスクはcronスクリプトによって自動的に実行されますが、それぞれのcron反復で実行される特定のタスクはスケジュールされたタスク設定により決定されます。Scheduled tasks are automatically run by the cron script, but the specific tasks which run on each cron iteration are determined by the scheduled tasks configuration. admin/cli/scheduled_task.phpスクリプトの使用でスケジュールタスク設定の上書きおよびスケジュールタスクの即時実行が可能です。It is possible to override the scheduled tasks configuration and run a single scheduled task immediately using the admin/cli/scheduled_task.php script.

This script accepts the following arguments: このスクリプトは以下の引数を受け付けます:

--list - list all the known scheduled tasks. The tasks are listed by the class name used to run the task. This class name is required as the argument to the next option in order to run a specific task immediately.
--list - 既知のスケジュールタスクすべてを一覧表示します。タスクはタスクの実行に使用されるクラス名で一覧表示されます。このクラス名は特定のタスクをすぐに実行するために 次のオプションの引数として必要です。
--execute=<task> - スケジュール設定に関係なく、単一のスケジュールタスクを直ちに実行します。--execute=<task> - Runs a single scheduled task immediately - regardless of scheduling settings. これは無効化されたタスクも実行します。This will even run disabled tasks. タスクはクラスタ上であっても、同じタスクの同時実行を防ぐためロックを使用します。Tasks will still use locking to prevent concurrent execution of the same task - even on clusters. <task>引数のフォーマットは上の-listオプションが返すものと同じにする必要があります。The format of the <task> argument must be the same as returned by the --list option above.
--disable=<task> - Disables a single scheduled task (New in 4.3 onwards). The format of the <task> argument must be the same as returned by the --list option above.
 --disable=<task> - 単一のスケジュールタスクを無効にします (4.3以降の新機能)。<task>引数のフォーマットは上の--listオプションが返すものと同じにする必要があります。
--enable=<task> - Enables a single scheduled task (New in 4.3 onwards). The format of the <task> argument must be the same as returned by the --list option above.
--enable=<task> - 単一のスケジュールタスクを有効にします (4.3以降の新機能)。<<task>引数のフォーマットは上の--listオプションが返すものと同じにする必要があります。
--showsql - Shows sql queries before they are execute
--showdebugging - Shows developer debugging info

Note: You must escape the "\" with an extra \ when using the --execute command. Take the following for example:

php admin/cli/scheduled_task.php --list

will return something like:

== List of scheduled tasks (http://yourserver.com/moodle) ==
\enrol_imsenterprise\task\cron_task                10 * * * * *      ASAP
\logstore_legacy\task\cleanup_task                 * 5 * * * *       ASAP
\logstore_standard\task\cleanup_task               * 4 * * * *       Wednesday, November 12, 2014, 4:35 AM
\mod_forum\task\cron_task                          * * * * * *       ASAP
\core\task\automated_backup_task                   50 * * * * *      ASAP

...

To run the first task in that list, you would execute

php admin/cli/scheduled_task.php --execute='\enrol_imsenterprise\task\cron_task'

Be aware of the single quotes. Without them, you would need to use double backlashes to avoid escaping by the shell.

Ad hoc tasks

Ad hoc tasks are low-latency tasks that are normally run by the cron. You can run just the queued ad hoc tasks with admin/cli/adhoc_task.php.

This script accepts the following options and arguments:

 -h, --help                Print out this help
     --showsql             Show sql queries before they are executed
     --showdebugging       Show developer level debugging information
 -e, --execute             Run all queued adhoc tasks
 -k, --keep-alive=N        Keep this script alive for N seconds and poll for new adhoc tasks
 -i  --ignorelimits        Ignore task_adhoc_concurrency_limit and task_adhoc_max_runtime limits
 -f, --force               Run even if cron is disabled

For example to run the currently queued ad hoc tasks:

sudo -u apache php admin/cli/adhoc_task.php -e

See also the improvements to ad hoc tasks in Scheduled_tasks#Ad_hoc_tasks

Database transfer

A command line script for Database transfer may be found in admin/tool/dbtransfer/cli/migrate.php.

Purge caches

You can purge caches using this script:

 php admin/cli/purge_caches.php

Kill all sessions

If needed for administrative reasons, you can kill all user sessions using this script:

php admin/cli/kill_all_sessions.php

As a result, all users will be logged out from Moodle.

Backup and restore of large courses

See Backup via CLI in Course backup and Restore via CLI in Course restore (new in 3.10 onwards).

Fix course / module sequences

In rare cases (such as after upgrading from a very old version of Moodle), the course / section / module sequence data can be out of sync. This can cause various problems for affected courses, such as sections not appearing, backups failing, pages not displaying etc. There is a specific check to check for errors caused by this problem, and to fix the data in the database if they are found. To run this script please use the command below:

 php admin/cli/fix_course_sequence.php -c=* --fix

This will check every course in Moodle and report which ones had errors and were fixed.

Fix orphaned question categories

When a quiz is created, a new question category for the quiz is automatically created. In versions of Moodle prior to 2.9.1, if the quiz is deleted, the question category and any questions in the category remain in database. These orphaned question categories may be fixed by running the admin/cli/fix_orphaned_question_categories.php script with the --fix option.

Search and replace text

This script can be used to search and replace text throughout the whole database. Use carefully and backup first always. More info in Search and replace tool.

 php admin/tool/replace/cli/replace.php --search=//oldsitehost --replace=//newsitehost

Build theme CSS cache

If Moodle is not running in theme designer mode it will keep a copy of the compiled CSS on local disk and serve that to the browser when it requests a page. If there isn't a copy on local disk then a copy will be built the first time a page within Moodle is requested.

With this script you can pre-compile the cached CSS files for themes within Moodle to avoid having a user wait for the theme to compile during the first page request.

 php admin/cli/build_theme_css.php --themes=boost

Get and set configuration values

Displays the current value of the given setting, or set the given setting to the specified value.

$ php admin/cli/cfg.php [--component=<componentname>] [--json] [--shell-arg]
$ php admin/cli/cfg.php --name=<configname> [--component=<componentname>] [--shell-arg] [--no-eol]
$ php admin/cli/cfg.php --name=<configname> [--component=<componentname>] --set=<value>
$ php admin/cli/cfg.php --name=<configname> [--component=<componentname>] --unset
$ php admin/cli/cfg.php [--help|-h]

Examples:

$ php admin/cli/cfg.php --name=langmenu

will display the value of Display language menu in Site administration > Language > Language settings (0 for No or 1 for Yes).

$ php cfg.php --name=maxsizetodownload --component=folder

will display the value of Maximum folder download size (MB) accessible from Site administration > Plugins > Activity modules > Folder.

$ php admin/cli/cfg.php --name=langmenu --set=0

will disable the Language menu.

E-mail flag for users

New in 4.2 The CLI script to change the email flag for one or many users at a time can be found on the page E-Mail flag for users

Dashboard reset

If you make changes to the dashboard and want all users to have their dashboard reset to reflect the changes this can be done on the cli:

php admin/cli/dashboard_reset.php -e

Managing plugins via command line

List and uninstall Moodle plugins

Moodle includes a handy command-line tool to display a list of plugins and remove plugins.

$ php admin/cli/uninstall_plugins.php

This command line tool accepts the following arguments.

Options:

    -h --help                   Print this help.
    --show-all                  Displays a list of all installed plugins.
    --show-contrib              Displays a list of all third-party installed plugins.
    --show-missing              Displays a list of plugins missing from disk.
    --purge-missing             Uninstall all missing from disk plugins.
    --plugins=<plugin name>     A comma separated list of plugins to be uninstalled. E.g. mod_assign,mod_forum
    --run                       Execute uninstall. If this option is not set, then the script will be run in a dry mode.
    --showsql                   Show sql queries before they are executed.
    --showdebugging             Show developer level debugging information.

Dry Mode does everything the script would normally do except for actually making any changes. This is useful when you want to test the validity of your command.

Run this command from the Moodle wwwroot directory. Here are some examples:

    # php admin/cli/uninstall_plugins.php  --show-all

        Prints tab-separated list of all installed plugins.

    # php admin/cli/uninstall_plugins.php  --show-contrib

        Prints tab-separated list of all third-party installed plugins.

    # php admin/cli/uninstall_plugins.php  --show-missing

        Prints tab-separated list of all missing from disk plugins.

    # php admin/cli/uninstall_plugins.php  --purge-missing

        A dry run of uninstalling all missing plugins. This will NOT uninstall the plugin. To actually uninstall, you need to add the '--run' arguments.

    # php admin/cli/uninstall_plugins.php  --purge-missing --run

        Run uninstall of all missing plugins.

    # php admin/cli/uninstall_plugins.php  --plugins=mod_assign,mod_forum

        A dry run of uninstalling mod_assign and mod_forum plugins. This will NOT uninstall the plugin. To actually uninstall, you need to add the '--run' arguments.

    # php admin/cli/uninstall_plugins.php  --plugins=mod_assign,mod_forum --run

        Run uninstall for mod_assign and mod_forum plugins.

This tool does not perform all of the steps needed to fully uninstall a plugin. You must then:

If you skip one or both of these steps, you will be prompted to update the Moodle database or re-install the plugin the next time you log in as a site administrator and access the Site Administration > Notifications page.

■■■■■■■■■■■■■■■■■■■■■■■■■■■■

CLIスクリプトの実行

Webサーバへのシェルアクセスがある場合、Moodleの管理中にさまざまなCLI(コマンドラインインターフェース)スクリプトが役立つ場合があります。コア管理CLIツールはadmin/cli/*フォルダにあります。他のプラグインは、独自のcliフォルダ内のスクリプトを介してCLI機能を提供します。たとえば、enrol_db同期スクリプトはenrol/db/cli/にあります。

アクセス制御の問題を回避するには、Webサーバプロセスの所有者としてそれらを実行する必要があります。 CLIのインストールとアップグレードでは、moodledataディレクトリに新しいファイルが作成され、Webサーバがそれらに書き込みアクセスできる必要があるため、特に重要です。 Linuxディストリビューションでは、Webサーバを実行するユーザは通常、apache、wwrun、httpdなどです。ルートとして、あなたはおそらく次のようなMoodleCLIスクリプトを実行したいと思うでしょう:

   $ cd /path/to/your/moodle/dir
   $ sudo -u apache /usr/bin/php admin/cli/somescript.php --params

ほとんどのスクリプトは、共通の--help(または-h)パラメータを受け入れて、完全な使用法情報を表示します。次に例を示します。

   $ sudo -u apache /usr/bin/php admin/cli/install.php --help
注意: これらのスクリプトは、WebサーバユーザのIDで実行されることになっています。このページの例では、説明のためにapacheユーザを使用しています。特定の値は、OSのディストリビューションとローカルセットアップによって異なります。一般的な値は、 apachewww-data、またはhttpdです。

アップグレード

Moodleはコマンドラインからアップグレードできます。インストールスクリプトと同様に、アップグレードには対話型モードまたは非対話型モードのいずれかがあります。スクリプト自体はサイトをメンテナンスモードにしません。自分で行う必要があります。また、スクリプトはデータをバックアップしません(このページを読んだ場合、おそらくmoodledataとデータベースをバックアップするための独自のスクリプトがいくつかありますよね?)

   $ sudo -u apache /usr/bin/php admin/cli/upgrade.php

MoodleソースコードのGitチェックアウトを使用する場合、コマンドラインからのアップグレードはMoodleアップグレードの非常に快適な方法です(管理者用Gitを参照)。 gitリポジトリで追跡された最終的なローカルカスタマイズを保持しながら、数秒以内にサイトを最新バージョンにアップグレードする方法については、次の手順を参照してください。

   $ cd /var/www/sites/moodle/htdocs/
   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable
   $ git pull
   $ sudo -u apache /usr/bin/php admin/cli/upgrade.php
   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable

インストール

コマンドラインからMoodleをインストールする方法は2つあります。インタラクティブモードでは、インストールスクリプトは新しいMoodleサイトを適切にセットアップするために必要なすべてのデータを要求します。非対話型モードでは、必要なすべてのデータをスクリプトパラメータとして指定する必要があります。そうすると、新しいサイトがサイレントインストールされます。パラメータは、インタラクティブモードでも渡すことができます。提供された値は、対話型セッション中にデフォルト値として使用されます。

   $ sudo -u apache /usr/bin/php admin/cli/install.php --lang=cs

必要に応じて、config.phpを入力するだけで、データベースのインストールをスキップできます。

  $ sudo -u apache /usr/bin/php admin/cli/install.php --skip-database

メンテナンスモード

CLIを介してサイトをメンテナンスモードに切り替えるには、次を使用できます。

   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enable

メンテナンスモードをオフにするには、-disableパラメータを指定して同じスクリプトを実行します。

   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --disable

メンテナンスモードをすぐに有効にしたくないが、ユーザにカウントダウンを表示する場合は、-enablelaterパラメータとカウントダウンを実行する分数を指定して同じスクリプトを実行します。

   $ sudo -u apache /usr/bin/php admin/cli/maintenance.php --enablelater=10

このスクリプトは、オフライン モードのclimaintenance.htmlファイルも作成および削除します。

オフラインモード

状況によっては、Moodleサイトをオフラインモードに切り替えて、Web経由でアクセスできないようにしたい場合がありますが、Webサーバを完全に停止することはできません(通常、他のWebページやアプリケーションが実行されているため)。 climaintenance.htmlというファイルがmoodledataディレクトリのルートフォルダに存在する場合、Moodleは他のページの代わりにそのファイルの内容を自動的に表示します。

   $ cd /var/www/sites/moodle/moodledata/
   $ echo '<h1>Sorry, maintenance in progress</h1>' > climaintenance.html

あなたはダウンしているサーバについてユーザに通知するための適切な形式のHTMLページを準備し、moodledataディレクトリにclimaintenance.offのような名前で保持し、必要に応じて名前をclimaintenance.htmlに変更できます。

カスタムサイトのデフォルト

CLIを介したインストールおよびアップグレード中に、Moodleは管理変数をデフォルト値に設定します。さまざまなデフォルトを使用できます。詳細については、MDL-17850を参照してください。間もなく、あなたがする必要があるのは、ファイルlocal/defaults.phpをMoodleインストールに追加することです。ファイルの形式は次のようになります

<?php $defaults['pluginname']['settingname'] = 'settingvalue'; // for plugins $defaults['moodle']['settingname'] = 'settingvalue'; // for core settings

これらのデフォルトは、インストール、アップグレード中に使用され、サイト管理ページにもデフォルトとして表示されます。

ユーザパスワードをリセット

管理者パスワードを忘れた場合(またはサイト上の他のユーザのパスワードを設定したい場合)は、reset_password.phpスクリプトを使用できます。スクリプトは、指定されたユーザに正しくソルトされたパスワードを設定します。

   $ sudo -u apache /usr/bin/php admin/cli/reset_password.php

MySQLストレージエンジンの変換

MySQLデータベースバックエンドでMoodleサイトを実行し、テーブルのストレージエンジンとしてデフォルトのMyISAMを使用する場合は、InnoDBなどのより信頼性の高いエンジンを使用するように変換することをお勧めします(実際には、PostgreSQLに切り替える必要があります;-)とにかく)。

   $ sudo -u apache /usr/bin/php admin/cli/mysql_engine.php --engine=InnoDB

InnoDBテーブルをBarracudaに変換する

ファイル形式としてAntelopeを使用するデータベーステーブルでMySQLを使用しているサイトでは、テーブルをBarracudaファイル形式に変換することをお勧めします。

これは、ファイル形式としてAntelopeを使用するテーブルは、10を超えるテキスト列を処理できないためです。このファイル形式は、下位互換性の理由から、 コンパクト および 冗長 行フォーマットのみをサポートします。これにより、コースをリストアするときに大規模なサイトで問題が発生する可能性があります。その場合、次のエラーが表示されます。

Row size too large (>8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help.

Barracudaは、最新のinnoDBファイル形式です。バラクーダは、コンパクト および冗長 行フォーマットをサポートすることに加えて、 圧縮 および 動的 行フォーマットもサポートします。

ただし、すべてのMySQLユーザが影響を受けるわけではないため、テーブルをBarracudaに変換することは推奨されるだけであり、必須ではありません。 (これは、大規模なサイトでのみ問題になる可能性があります。)

テーブルを変換するためのツール

テーブルをBarracudaに変換するためのコマンドラインツールがMoodleに含まれています。

変換が必要なテーブルを表示するには、リストオプションを使用します。

$ php admin/cli/mysql_compressed_rows.php --list

出力例を次に示します。

mdl_data                            Compact     (needs fixing) 
mdl_data_fields                     Compact     (needs fixing)
mdl_enrol_paypal                    Compact     (needs fixing)

変換を続行するには、修正オプションを使用してコマンドを実行します。

$ php admin/cli/mysql_compressed_rows.php --fix

成功したテーブル変換は、出力で報告されます。次に例を示します。

mdl_data                   ... Compressed
mdl_data_fields            ... Compressed
mdl_enrol_paypal           ... Compressed

コマンドはmoodleディレクトリで実行する必要があることに注意してください。テーブルが修正されると、警告メッセージは表示されなくなります。

InnoDBファイル形式の詳細については、MySQL InnoDBグロッサリー-AntelopeおよびMySQL InnoDB用語集-バラクーダを参照してください。

これらのコマンドを実行するための十分なパーミッションがないためにエラーが発生した場合(これは非常に可能性が高いです)、最も簡単な解決策は、を使用して必要なSQLコマンドを生成することです。

$ php admin/cli/mysql_compressed_rows.php --showsql

次に、生成されたSQLを 'root' ユーザとして実行されているmysqlクライアントにコピーできます。

新しい文字セットと照合順序への変換

$ php admin/cli/mysql_collation.php --collation=utf8mb4_unicode_ci

コマンドラインからcronを実行する

バージョン1.xでは、コマンドラインまたはWeb経由でadmin/cron.phpを実行できました。 Moodle 2.0以降、コマンドラインから実行できるのはadmin/cli/cron.phpスクリプトのみです。

スケジュールされたタスク

スケジュールされたタスクはcronスクリプトによって自動的に実行されますが、各cron反復で実行される特定のタスクは、スケジュールされたタスクの構成によって決定されます。 admin/tool/task/cli/schedule_task.phpスクリプトを使用して、スケジュールされたタスクの構成を上書きし、単一のスケジュールされたタスクをすぐに実行することができます。

このスクリプトは、次の引数を受け入れます。

--list - list all the known scheduled tasks. The tasks are listed by the class name used to run the task. This class name is required as the argument to the next option in order to run a specific task immediately.
--execute=<task> - Runs a single scheduled task immediately - regardless of scheduling settings. This will even run disabled tasks. Tasks will still use locking to prevent concurrent execution of the same task - even on clusters. The format of the <task> argument must be the same as returned by the --list option above.
--showsql - Shows sql queries before they are execute
--showdebugging - Shows developer debugging info

注: --executeコマンドを使用する場合は、追加の\を使用して "\"をエスケープする必要があります。たとえば、次のようにします。

php admin/tool/task/cli/schedule_task.php --list

次のようなものが返されます:

== List of scheduled tasks (http://yourserver.com/moodle) ==
\enrol_imsenterprise\task\cron_task                10 * * * * *      ASAP
\logstore_legacy\task\cleanup_task                 * 5 * * * *       ASAP
\logstore_standard\task\cleanup_task               * 4 * * * *       Wednesday, November 12, 2014, 4:35 AM
\mod_forum\task\cron_task                          * * * * * *       ASAP
\core\task\automated_backup_task                   50 * * * * *      ASAP

...

そのリストの最初のタスクを実行するには、次を実行します

php admin/tool/task/cli/schedule_task.php --execute='\enrol_imsenterprise\task\cron_task'

一重引用符に注意してください。それらがないと、シェルによるエスケープを回避するために、二重のバックラッシュを使用する必要があります。

データベース移行

データベース移行のコマンドラインスクリプトは、admin/tool/dbtransfer/cli/migrate.php です。

キャッシュを削除

次のスクリプトを使用して、キャッシュをパージできます。

 php admin/cli/purge_caches.php

すべてのセッションを強制終了します

管理上の理由で必要な場合は、次のスクリプトを使用してすべてのユーザセッションを強制終了できます。

php admin/cli/kill_all_sessions.php

その結果、すべてのユーザがMoodleからログアウトされます。

コース/モジュールシーケンスの修正

まれに(非常に古いバージョンのMoodleからアップグレードした後など)、コース/セクション/モジュールのシーケンスデータが同期していない可能性があります。これにより、セクションが表示されない、バックアップが失敗する、ページが表示されないなど、影響を受けるコースにさまざまな問題が発生する可能性があります。この問題によって引き起こされるエラーをチェックし、見つかった場合はデータベース内のデータを修正するための特定のチェックがあります。このスクリプトを実行するには、以下のコマンドを使用してください。

 php admin/cli/fix_course_sequence.php -c=* --fix

これにより、Moodleのすべてのコースがチェックされ、エラーが発生して修正されたコースが報告されます。

孤立した問題カテゴリを修正

小テストが作成されると、小テストの新しい問題カテゴリが自動的に作成されます。 2.9.1より前のバージョンのMoodleでは、小テストが削除された場合、問題カテゴリとそのカテゴリ内の問題はデータベースに残ります。これらの孤立した問題カテゴリは、-fixオプションを指定してadmin/cli /fix_alone_question_categories.phpスクリプトを実行することで修正できます。

テキストの検索と置換

このスクリプトを使用して、データベース全体のテキストを検索および置換できます。慎重に使用し、常に最初にバックアップしてください。詳細については、検索および置換ツールをご覧ください。

 php admin/tool/replace/cli/replace.php --search=//oldsitehost --replace=//newsitehost

ビルドテーマCSSキャッシュ

Moodleがテーマデザイナーモードで実行されていない場合、コンパイルされたCSSのコピーをローカルディスクに保持し、ページを要求したときにそれをブラウザーに提供します。ローカルディスクにコピーがない場合、Moodle内のページが最初にリクエストされたときにコピーが作成されます。

このスクリプトを使用すると、Moodle内のテーマのキャッシュされたCSSファイルを事前にコンパイルして、最初のページのリクエスト中にテーマがコンパイルされるのをユーザが待たないようにすることができます。

 php admin/cli/build_theme_css.php --themes=boost

構成値の取得と設定

指定された設定の現在の値を表示するか、指定された設定を指定された値に設定します。

例:

 php admin/cli/cfg.php [--component=<componentname>] [--json] [--shell-arg]
 php admin/cli/cfg.php --name=<configname> [--component=<componentname>] [--shell-arg] [--no-eol]
 php admin/cli/cfg.php --name=<configname> [--component=<componentname>] --set=<value>
 php admin/cli/cfg.php --name=<configname> [--component=<componentname>] --unset
 php admin/cli/cfg.php [--help|-h]

関連項目

  • MDL-35736 - コマンドラインからプラグインを管理する
  • MDL-36237 - CLIによるリゾートコースリスト
  • MOOSH - MOOdleシェル。これは、最も一般的なMoodleタスクを実行できるようにするコマンドラインツールです。