craftcms/cms

[4.x] & [5.x]: General config: `backupCommand` setting to `Closure` ineffective

Closed this issue · 3 comments

What happened?

Description

The docs for 4.x & 5.x state that General Config backupCommand can be set to a \Closure: https://craftcms.com/docs/4.x/config/general.html#backupcommand & https://craftcms.com/docs/5.x/reference/config/general.html#backupcommand

However, when this config item is pulled in:

cms/src/db/Connection.php

Lines 292 to 298 in 20da3b2

$backupCommand = Craft::$app->getConfig()->getGeneral()->backupCommand;
if ($backupCommand === false) {
throw new Exception('Database not backed up because the backup command is false.');
} elseif ($backupCommand === null || $backupCommand instanceof \Closure) {
$backupCommand = $this->getSchema()->getDefaultBackupCommand($event->ignoreTables);
}

The \Closure is not resolved, it's over-written.

Expected behavior

\Closure called and the result used.

Craft CMS version

5.1.10 & 4.9.7

PHP version

N/A

Operating system and version

N/A

Database type and version

MySQL 8.0.37

Image driver and version

N/A

Installed plugins and versions

N/A

Looks like this commit reverted what should previously have worked: 97da6ca#diff-61f94e4b1825f1dc2ece99a882e0787dbd2a0ebe311fcb4b75ca865b6e1d0002

@rob-baker-ar can you share you config It works as expected for me:

Example swapping mysqldump for xtrabackup, keeping all args:

<?php
use craft\config\GeneralConfig;

return GeneralConfig::create()
    ->backupCommand(fn(\mikehaertl\shellcommand\Command $command) =>
        $command->setCommand('xtrabackup'));

The \Closure is not resolved, it's over-written.

The Closure is applied here: https://github.com/craftcms/cms/blob/5.x/src/db/mysql/Schema.php#L229-L232

Right, that's my mistake. Apologies - long day - I had been swapping various parts of that file in and out of the version we have on one of our sites to see if it got me past an issue I was trying to resolve (related to this: #12557 - trying to get backups back into a transaction) and I had assumed that the Closure was applied in the place I referred to - it was at one point, but not anymore!

Closing.