public function init($options = [])
{
$this->setOptions($options);
// create backup directory if not exists
if (!is_dir(PIMCORE_BACKUP_DIRECTORY)) {
if (!\Pimcore\File::mkdir(PIMCORE_BACKUP_DIRECTORY)) {
Logger::err("Directory " . PIMCORE_BACKUP_DIRECTORY . " does not exists and cannot be created.");
exit;
}
}
$errors = [];
$this->setFileAmount(0);
// cleanup old backups
if (is_file(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/backup-dump.sql")) {
unlink(PIMCORE_SYSTEM_TEMP_DIRECTORY . "/backup-dump.sql");
}
// get steps
$steps = [];
// get available tables
$db = Db::get();
$tables = $this->getTables();
$steps[] = ["mysql-tables", $this->options['mysql-tables']];
// tables
foreach ($tables as $table) {
$name = current($table);
$type = next($table);
if ($type != "VIEW") {
$steps[] = ["mysql", ["name" => $name, "type" => $type]];
}
}
// views
foreach ($tables as $table) {
reset($table);
$name = current($table);
$type = next($table);
if ($type == "VIEW") {
$steps[] = ["mysql", ["name" => $name, "type" => $type]];
}
}
$steps[] = ["mysql-complete", null];
if (!$options['only-mysql-related-tasks']) {
// check files
$currentFileCount = 0;
$currentFileSize = 0;
$currentStepFiles = [];
// check permissions
$filesIn = rscandir(PIMCORE_DOCUMENT_ROOT . "/");
clearstatcache();
foreach ($filesIn as $fileIn) {
if (!is_readable($fileIn)) {
$errors[] = $fileIn . " is not readable.";
}
if ($currentFileCount > 300 || $currentFileSize > 20000000) {
$currentFileCount = 0;
$currentFileSize = 0;
if (!empty($currentStepFiles)) {
$filesToBackup[] = $currentStepFiles;
}
$currentStepFiles = [];
}
if (file_exists($fileIn)) {
$currentFileSize += filesize($fileIn);
$currentFileCount++;
$currentStepFiles[] = $fileIn;
}
}
if (!empty($currentStepFiles)) {
$filesToBackup[] = $currentStepFiles;
}
$this->setFilesToBackup($filesToBackup);
$fileSteps = count($filesToBackup);
for ($i = 0; $i < $fileSteps; $i++) {
$steps[] = ["files", ["step" => $i]];
}
$steps[] = ["complete", null];
}
if (!empty($errors)) {
$steps = null;
}
return ["steps" => $steps, "errors" => $errors];
}