1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kanboard_ynh.git synced 2024-09-03 19:36:17 +02:00
kanboard_ynh/sources/vendor/PicoDb/Schema.php
2014-10-22 19:59:09 +02:00

54 lines
No EOL
1.2 KiB
PHP

<?php
namespace PicoDb;
class Schema
{
protected $db = null;
public function __construct(Database $db)
{
$this->db = $db;
}
public function check($last_version = 1)
{
$current_version = $this->db->getConnection()->getSchemaVersion();
if ($current_version < $last_version) {
return $this->migrateTo($current_version, $last_version);
}
return true;
}
public function migrateTo($current_version, $next_version)
{
try {
$this->db->startTransaction();
for ($i = $current_version + 1; $i <= $next_version; $i++) {
$function_name = '\Schema\version_'.$i;
if (function_exists($function_name)) {
call_user_func($function_name, $this->db->getConnection());
$this->db->getConnection()->setSchemaVersion($i);
}
}
$this->db->closeTransaction();
}
catch (\PDOException $e) {
$this->db->setLogMessage($function_name.' => '.$e->getMessage());
$this->db->cancelTransaction();
return false;
}
return true;
}
}