PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / helpers / src / backup / export / rule / sqlfile.php

sqlfile.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/helpers/src/backup/export/rule/sqlfile.php

90 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * SQL Backup export rule, apposite for huge queries.
16 *
17 * @since 1.5
18 */
19 class VBOBackupExportRuleSqlfile extends VBOBackupExportRuleSql
20 {
21 /**
22 * The path of the file containing the export queries.
23 *
24 * @var string
25 */
26 private $path;
27
28 /**
29 * Returns the rules instructions.
30 *
31 * @return mixed
32 */
33 public function getData()
34 {
35 // check whether the file has been saved
36 if ($this->path)
37 {
38 // return an associative array specifying the file path
39 // that contains all the export queries
40 return [
41 'path' => $this->path,
42 ];
43 }
44
45 // do not import empty files
46 return null;
47 }
48
49 /**
50 * Helper method used to register the query inside the buffer.
51 *
52 * @param string $query The query to register.
53 *
54 * @return void
55 */
56 protected function registerQuery($query)
57 {
58 // register query through parent
59 parent::registerQuery($query);
60
61 if (!$this->queries)
62 {
63 // nothing to export
64 return;
65 }
66
67 if (!$this->path)
68 {
69 // build file path only once
70 $this->path = 'database/' . $this->table . '.sql';
71 }
72
73 // create buffer to save
74 $buffer = trim(implode("\n\n", $this->queries));
75 $buffer = preg_replace("/\)\s*,\s*\(/", "),\n(", $buffer);
76
77 // register SQL buffer into the archive
78 $saved = $this->archive->addBuffer($buffer . "\n\n", $this->path);
79
80 if (!$saved)
81 {
82 // an error occurred while writing the dump files
83 throw new Exception(sprintf('Unable to write dump into: %s', $this->path), 500);
84 }
85
86 // reset queries list to avoid duplicates
87 $this->queries = [];
88 }
89 }
90