sqlfile.php
83 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 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 | VAPLoader::import('libraries.backup.import.rule.sql'); |
| 15 | |
| 16 | /** |
| 17 | * Backup SQL File import rule. |
| 18 | * |
| 19 | * @since 1.7.1 |
| 20 | */ |
| 21 | class VAPBackupImportRuleSqlfile extends VAPBackupImportRuleSql |
| 22 | { |
| 23 | /** |
| 24 | * Executes the backup import command. |
| 25 | * |
| 26 | * @param mixed $data The import rule instructions. |
| 27 | * |
| 28 | * @return void |
| 29 | */ |
| 30 | public function execute($data) |
| 31 | { |
| 32 | if (empty($data->path)) |
| 33 | { |
| 34 | // missing file path |
| 35 | throw new Exception('Invalid SQL File import rule, path missing', 500); |
| 36 | } |
| 37 | |
| 38 | // set up the path from which the SQL queries should be loaded |
| 39 | $path = JPath::clean($this->path . '/' . $data->path); |
| 40 | |
| 41 | if (!JFile::exists($path)) |
| 42 | { |
| 43 | // file not found |
| 44 | throw new Exception(sprintf('Invalid SQL File import rule, file [%s] not found', $path), 404); |
| 45 | } |
| 46 | |
| 47 | $buffer = ''; |
| 48 | |
| 49 | // open file |
| 50 | $fp = fopen($path, 'r'); |
| 51 | |
| 52 | while (!feof($fp)) |
| 53 | { |
| 54 | // read from file and copy into the buffer |
| 55 | $buffer .= fread($fp, 8192); |
| 56 | } |
| 57 | |
| 58 | // close file |
| 59 | fclose($fp); |
| 60 | |
| 61 | $queries = []; |
| 62 | |
| 63 | // split SQL queries into an array according to the platform in use |
| 64 | if (VersionListener::isJoomla()) |
| 65 | { |
| 66 | $queries = JDatabaseDriver::splitSql($buffer); |
| 67 | } |
| 68 | else if (VersionListener::isWordpress()) |
| 69 | { |
| 70 | $queries = JDatabaseHelper::splitSql($buffer); |
| 71 | } |
| 72 | |
| 73 | // free some space |
| 74 | unset($buffer); |
| 75 | |
| 76 | // execute queries through the parent |
| 77 | parent::execute($queries); |
| 78 | |
| 79 | // free some space |
| 80 | unset($queries); |
| 81 | } |
| 82 | } |
| 83 |