move ADOdb row_lock and rollback_lock methods to Db class, use Db::$tablealiases and use them for backup, also added a "backup_(starts|finished)" hook for apps

This commit is contained in:
Ralf Becker 2016-10-13 17:54:58 +02:00
parent b29461f013
commit dca8f4dd70
2 changed files with 73 additions and 2 deletions

View File

@ -852,6 +852,70 @@ class Db
return $this->Link_ID->FailTrans();
}
/**
* Lock a rows in table
*
* Will escalate and lock the table if row locking not supported.
* Will normally free the lock at the end of the transaction.
*
* @param string $table name of table to lock
* @param string $where ='true' where clause to use, eg: "WHERE row=12". Defaults to lock whole table.
* @param string $col ='1 as adodbignore'
*/
function row_lock($table, $where='true', $col='1 as adodbignore')
{
if (!$this->Link_ID && !$this->connect())
{
return False;
}
if (self::$tablealiases && isset(self::$tablealiases[$table]))
{
$table = self::$tablealiases[$table];
}
return $this->Link_ID->RowLock($table, $where, $col);
}
/**
* Commit changed rows in table
*
* @param string $table
* @return boolean
*/
function commit_lock($table)
{
if (!$this->Link_ID && !$this->connect())
{
return False;
}
if (self::$tablealiases && isset(self::$tablealiases[$table]))
{
$table = self::$tablealiases[$table];
}
return $this->Link_ID->CommitLock($table);
}
/**
* Unlock rows in table
*
* @param string $table
* @return boolean
*/
function rollback_lock($table)
{
if (!$this->Link_ID && !$this->connect())
{
return False;
}
if (self::$tablealiases && isset(self::$tablealiases[$table]))
{
$table = self::$tablealiases[$table];
}
return $this->Link_ID->RollbackLock($table);
}
/**
* Find the primary key of the last insertion on the current db connection
*

View File

@ -931,6 +931,9 @@ class Backup
fwrite($f,"\nschema: ".json_encode($this->schemas)."\n");
// let apps know that backup is about to start
Api\Hooks::process('backup_starts', array(), true);
foreach($this->schemas as $table => $schema)
{
if (in_array($table,$this->exclude_tables)) continue; // dont backup
@ -943,7 +946,7 @@ class Backup
if ($lock_table || empty($pk) && is_null($lock_table))
{
$this->db->Link_ID->RowLock($table, 'true'); // PostgreSQL drive from ADOdb requires 2. param $where!
$this->db->Link_ID->row_lock($table);
}
$total = $max = 0;
do {
@ -970,8 +973,12 @@ class Backup
}
while((!empty($pk) || $lock_table !== false) && !($total % self::ROW_CHUNK) && $num_rows);
if (!$pk) $this->db->Link_ID->RollbackLock($table);
if (!$pk) $this->db->rollback_lock($table);
}
// let apps know that backup is finished
Api\Hooks::process('backup_finished', array(), true);
if(!$zippresent) // save without files
{
if ($this->backup_files)