fix: [DEFAULT_DIR] resolves to JPATH_ROOT/backups, shown as placeholder
- getDefaultAbsolute() now returns JPATH_ROOT/backups instead of the old admin component directory - SQL default, form default, and install migration all use [DEFAULT_DIR] - portablize() converts ./backups and old literal paths back to [DEFAULT_DIR] - Users see [DEFAULT_DIR] in the field, resolved path shown in status
This commit is contained in:
@@ -67,7 +67,7 @@
|
||||
type="FolderPicker"
|
||||
label="COM_MOKOJOOMBACKUP_FIELD_BACKUP_DIR"
|
||||
description="COM_MOKOJOOMBACKUP_FIELD_BACKUP_DIR_DESC"
|
||||
default="./backups"
|
||||
default="[DEFAULT_DIR]"
|
||||
addfieldprefix="Joomla\Component\MokoSuiteBackup\Administrator\Field"
|
||||
/>
|
||||
<field
|
||||
|
||||
@@ -6,7 +6,7 @@ CREATE TABLE IF NOT EXISTS `#__mokosuitebackup_profiles` (
|
||||
`archive_format` VARCHAR(10) NOT NULL DEFAULT 'zip',
|
||||
`compression_level` TINYINT(1) UNSIGNED NOT NULL DEFAULT 5 COMMENT '0=none, 9=max',
|
||||
`split_size` INT(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '0=no split, otherwise MB per part',
|
||||
`backup_dir` VARCHAR(512) NOT NULL DEFAULT './backups',
|
||||
`backup_dir` VARCHAR(512) NOT NULL DEFAULT '[DEFAULT_DIR]',
|
||||
`archive_name_format` VARCHAR(512) NOT NULL DEFAULT '[host]_[datetime]_profile[profile_id]' COMMENT 'Filename format with placeholders',
|
||||
`exclude_dirs` TEXT NOT NULL COMMENT 'Newline-separated directory paths to exclude',
|
||||
`exclude_files` TEXT NOT NULL COMMENT 'Newline-separated filename patterns to exclude',
|
||||
@@ -81,7 +81,7 @@ INSERT IGNORE INTO `#__mokosuitebackup_profiles` (
|
||||
`published`, `ordering`, `created`, `modified`
|
||||
) VALUES (
|
||||
1, 'Default Backup Profile', 'Full site backup with default settings', 'full',
|
||||
'zip', 5, 0, './backups',
|
||||
'zip', 5, 0, '[DEFAULT_DIR]',
|
||||
'administrator/components/com_mokosuitebackup/backups\ntmp\ncache\nlogs\nadministrator/logs',
|
||||
'.gitignore\n.htaccess.bak',
|
||||
'#__session',
|
||||
|
||||
@@ -39,7 +39,7 @@ HTACCESS;
|
||||
*/
|
||||
public static function getDefaultAbsolute(): string
|
||||
{
|
||||
return JPATH_ADMINISTRATOR . '/components/com_mokosuitebackup/backups';
|
||||
return JPATH_ROOT . '/backups';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,19 +125,19 @@ HTACCESS;
|
||||
*/
|
||||
public static function portablize(string $dir): string
|
||||
{
|
||||
// Replace the old literal default with the relative default
|
||||
$oldDefault = 'administrator/components/com_mokosuitebackup/backups';
|
||||
$oldDefaultAlt = 'administrator/components/com_mokojoombackup/backups';
|
||||
// Known defaults all map back to [DEFAULT_DIR]
|
||||
$knownDefaults = [
|
||||
self::PLACEHOLDER,
|
||||
self::DEFAULT_RELATIVE,
|
||||
'./backups',
|
||||
'backups',
|
||||
'administrator/components/com_mokosuitebackup/backups',
|
||||
'administrator/components/com_mokojoombackup/backups',
|
||||
self::getDefaultAbsolute(),
|
||||
];
|
||||
|
||||
if ($dir === $oldDefault || $dir === $oldDefaultAlt || $dir === self::PLACEHOLDER) {
|
||||
return self::DEFAULT_RELATIVE;
|
||||
}
|
||||
|
||||
// Replace absolute default path with relative default
|
||||
$absDefault = self::getDefaultAbsolute();
|
||||
|
||||
if ($dir === $absDefault) {
|
||||
return self::DEFAULT_RELATIVE;
|
||||
if (\in_array($dir, $knownDefaults, true)) {
|
||||
return self::PLACEHOLDER;
|
||||
}
|
||||
|
||||
// Replace absolute HOME prefix with [HOME]
|
||||
|
||||
+5
-4
@@ -233,11 +233,12 @@ class Pkg_MokoSuiteBackupInstallerScript
|
||||
{
|
||||
try {
|
||||
$db = Factory::getDbo();
|
||||
// Check for profiles using the old in-webroot default
|
||||
// Check for profiles using old literal defaults — migrate to [DEFAULT_DIR]
|
||||
$oldDefaults = [
|
||||
'administrator/components/com_mokosuitebackup/backups',
|
||||
'administrator/components/com_mokojoombackup/backups',
|
||||
'[DEFAULT_DIR]',
|
||||
'./backups',
|
||||
'backups',
|
||||
];
|
||||
$query = $db->getQuery(true)
|
||||
->select('COUNT(*)')
|
||||
@@ -250,10 +251,10 @@ class Pkg_MokoSuiteBackupInstallerScript
|
||||
$db->setQuery($query);
|
||||
|
||||
if ((int) $db->loadResult() > 0) {
|
||||
// Auto-migrate old defaults to the new ./backups convention
|
||||
// Auto-migrate old defaults to [DEFAULT_DIR] placeholder
|
||||
$update = $db->getQuery(true)
|
||||
->update($db->quoteName('#__mokosuitebackup_profiles'))
|
||||
->set($db->quoteName('backup_dir') . ' = ' . $db->quote('./backups'))
|
||||
->set($db->quoteName('backup_dir') . ' = ' . $db->quote('[DEFAULT_DIR]'))
|
||||
->where('(' . $db->quoteName('backup_dir') . ' IN ('
|
||||
. implode(',', array_map([$db, 'quote'], $oldDefaults))
|
||||
. ') OR ' . $db->quoteName('backup_dir') . ' = ' . $db->quote('')
|
||||
|
||||
Reference in New Issue
Block a user