diff --git a/api/src/Db.php b/api/src/Db.php index d7062e87f0..a812591fab 100644 --- a/api/src/Db.php +++ b/api/src/Db.php @@ -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 * diff --git a/api/src/Db/Backup.php b/api/src/Db/Backup.php index a93d8cac4f..419b3b59aa 100644 --- a/api/src/Db/Backup.php +++ b/api/src/Db/Backup.php @@ -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)