chg: [settingTable] Gracefully handle if file not writeable

cli-modification-summary
Sami Mokaddem 2022-02-07 11:11:25 +01:00
parent 14ec995c2b
commit 336dfb091c
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 14 additions and 3 deletions

View File

@ -3,6 +3,7 @@ namespace App\Model\Table;
use App\Model\Table\AppTable;
use Cake\ORM\Table;
use Cake\Filesystem\File;
use Cake\Core\Configure;
use Cake\Error\Debugger;
@ -85,6 +86,8 @@ class SettingsTable extends AppTable
if (!empty($setting['afterSave'])) {
$this->SettingsProvider->evaluateFunctionForSetting($setting['afterSave'], $setting);
}
} else {
$errors[] = __('Could not save settings on disk');
}
}
return $errors;
@ -129,8 +132,16 @@ class SettingsTable extends AppTable
$settings = $this->readSettings();
$settings[$name] = $value;
$settings = json_encode($settings, JSON_PRETTY_PRINT);
file_put_contents(CONFIG . 'config.json', $settings);
$this->loadSettings();
return true;
$path = CONFIG . 'config.json';
$file = new File($path);
if ($file->writable()) {
$success = file_put_contents($path, $settings);
if ($success) {
$this->loadSettings();
}
} else {
$success = false;
}
return $success;
}
}