Revision = 0;
$this->Trace = array();
$this->VersionTable = 'SystemVersion';
$this->InstallMethod = 'FullInstall';
$this->InsertSampleDataMethod = 'InsertSampleData';
}
function GetDbVersion()
{
$DbResult = $this->Database->select($this->VersionTable, '*', 'Id=1');
$Version = $DbResult->fetch_assoc();
return($Version['Revision']);
}
function IsInstalled()
{
$DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->VersionTable.'"');
return($DbResult->num_rows > 0);
}
function IsUpToDate()
{
return($this->Revision <= $this->GetDbVersion());
}
function Upgrade()
{
$DbRevision = $this->GetDbVersion();
$Output = 'Počáteční revize databáze: '.$DbRevision.'
';
while($this->Revision > $DbRevision)
{
$TraceItem = $this->Trace[$DbRevision];
$Output .= 'Aktualizace na verzi '.$TraceItem['Revision'].':
';
// Show applied SQL queries immediatelly
echo($Output);
$Output = '';
$RevUpdate = $TraceItem['Function'];
$RevUpdate($this);
$DbRevision = $TraceItem['Revision'];
$this->Database->query('UPDATE `'.$this->VersionTable.'` SET `Revision`= '.
$TraceItem['Revision'].' WHERE `Id`=1');
}
return($Output);
}
function Install()
{
$InstallMethod = $this->InstallMethod;
$InstallMethod($this);
$this->Update();
}
function Uninstall()
{
}
function InsertSampleData()
{
$InstallMethod = $this->InsertSampleDataMethod;
$InstallMethod($this);
}
function Execute($Query)
{
echo($Query.';
');
flush();
return($this->Database->query($Query));
}
}