mirror of
https://github.com/processwire/processwire.git
synced 2025-08-10 08:44:46 +02:00
Minor improvements to WireDatabaseBackup class
This commit is contained in:
@@ -359,7 +359,7 @@ class WireDatabaseBackup {
|
||||
*
|
||||
* #pw-advanced
|
||||
*
|
||||
* @return null|\PDO|WireDatabasePDO
|
||||
* @return \PDO
|
||||
* @throws \Exception
|
||||
*
|
||||
*/
|
||||
@@ -482,17 +482,18 @@ class WireDatabaseBackup {
|
||||
*
|
||||
* #pw-group-reporting
|
||||
*
|
||||
* @return array of strings (basenames)
|
||||
* @param bool $getObjects Get SplFileInfo objects rather than basenames? (3.0.214+)
|
||||
* @return array|\SplFileInfo[] Array of strings (basenames), or array of SplFileInfo objects (when requested)
|
||||
*
|
||||
*/
|
||||
public function getFiles() {
|
||||
public function getFiles($getObjects = false) {
|
||||
$dir = new \DirectoryIterator($this->path);
|
||||
$files = array();
|
||||
foreach($dir as $file) {
|
||||
if($file->isDot() || $file->isDir()) continue;
|
||||
$key = $file->getMTime();
|
||||
while(isset($files[$key])) $key++;
|
||||
$files[$key] = $file->getBasename();
|
||||
$files[$key] = ($getObjects ? $file : $file->getBasename());
|
||||
}
|
||||
krsort($files); // sort by date, newest to oldest
|
||||
return array_values($files);
|
||||
@@ -552,7 +553,8 @@ class WireDatabaseBackup {
|
||||
fclose($fp);
|
||||
|
||||
// footer summary
|
||||
$pos = strpos($foot, self::fileFooter) + strlen(self::fileFooter);
|
||||
$pos = strpos($foot, self::fileFooter);
|
||||
if($pos !== false) $pos += strlen(self::fileFooter);
|
||||
if($info['valid'] && $pos !== false) {
|
||||
$json = substr($foot, $pos);
|
||||
$summary = json_decode($json, true);
|
||||
@@ -1090,7 +1092,7 @@ class WireDatabaseBackup {
|
||||
*
|
||||
* @param string $filename Filename to restore (must be SQL file exported by this class)
|
||||
* @param array $options See $restoreOptions
|
||||
* @return true on success, false on failure. Call the errors() method to retrieve errors.
|
||||
* @return bool True on success, false on failure. Call the errors() method to retrieve errors.
|
||||
*
|
||||
*/
|
||||
protected function restoreExec($filename, array $options = array()) {
|
||||
@@ -1163,7 +1165,7 @@ class WireDatabaseBackup {
|
||||
}
|
||||
|
||||
$inserts = $this->findInserts($filename1);
|
||||
foreach($inserts as $table => $tableInserts) {
|
||||
foreach($inserts as /*$table =>*/ $tableInserts) {
|
||||
foreach($tableInserts as $insert) {
|
||||
if(!$this->executeQuery($insert, $options)) $numErrors++;
|
||||
}
|
||||
@@ -1264,7 +1266,7 @@ class WireDatabaseBackup {
|
||||
*
|
||||
* @param string $filename to extract all CREATE TABLE statements from
|
||||
* @param array $options
|
||||
* @return bool|array of CREATE TABLE statements, associative: indexed by table name
|
||||
* @return array of CREATE TABLE statements, associative: indexed by table name
|
||||
* @throws \Exception if unable to open specified file
|
||||
*
|
||||
*/
|
||||
|
Reference in New Issue
Block a user