mirror of
https://github.com/chylex/Lightning-Tracker.git
synced 2025-08-17 05:31:42 +02:00
.github
.idea
build
dev
res
src
Configuration
Data
Database
Logging
Pages
Routing
Session
Update
Migrations
Tasks
AbstractMigrationProcess.php
AbstractMigrationTask.php
MigrationManager.php
Validation
.htaccess
bootstrap.php
index.php
install.php
update.php
utils.php
tests
.gitattributes
.gitignore
LICENSE
README.md
codecept.bat
codeception.yml
composer.json
composer.lock
54 lines
1.1 KiB
PHP
54 lines
1.1 KiB
PHP
<?php
|
|
declare(strict_types = 1);
|
|
|
|
namespace Update;
|
|
|
|
use Configuration\VersionFile;
|
|
use Exception;
|
|
|
|
final class MigrationManager{
|
|
private int $current_version;
|
|
private int $current_task;
|
|
|
|
public function __construct(int $current_version, int $current_task){
|
|
$this->current_version = $current_version;
|
|
$this->current_task = $current_task;
|
|
}
|
|
|
|
public function getCurrentVersion(): int{
|
|
return $this->current_version;
|
|
}
|
|
|
|
public function getCurrentTask(): int{
|
|
return $this->current_task;
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function finishVersion(): void{
|
|
++$this->current_version;
|
|
$this->current_task = 0;
|
|
$this->writeFile();
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function finishTask(): void{
|
|
++$this->current_task;
|
|
$this->writeFile();
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
private function writeFile(): void{
|
|
if (!(new VersionFile($this->current_version, $this->current_task))->writeSafe(VERSION_FILE, VERSION_TMP_FILE)){
|
|
throw new Exception('Error updating version file (migration '.$this->current_version.', task '.$this->current_task.').');
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|