Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| tao_install_utils_CustomProceduresParser | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 1 |
| parse | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
| 19 | * (under the project TAO & TAO2); |
| 20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
| 21 | * (under the project TAO-TRANSFER); |
| 22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | /** |
| 28 | * This SQL Parser is able to deal with Functions |
| 29 | * for PostgresSQL in a compliant SQL file. |
| 30 | * |
| 31 | * @author Jerome BOGAERTS <jerome.bogaerts@tudor.lu> |
| 32 | * @package tao |
| 33 | |
| 34 | */ |
| 35 | |
| 36 | class tao_install_utils_CustomProceduresParser extends tao_install_utils_SQLParser |
| 37 | { |
| 38 | /** |
| 39 | * Parse a SQL file containing mySQL compliant Procedures or Functions. |
| 40 | * @return void |
| 41 | * @throws tao_install_utils_SQLParsingException |
| 42 | */ |
| 43 | public function parse() |
| 44 | { |
| 45 | $this->setStatements([]); |
| 46 | $file = $this->getFile(); |
| 47 | |
| 48 | if (!file_exists($file)) { |
| 49 | throw new tao_install_utils_SQLParsingException("SQL file '${file}' does not exist."); |
| 50 | } elseif (!is_readable($file)) { |
| 51 | throw new tao_install_utils_SQLParsingException("SQL file '${file}' is not readable."); |
| 52 | } elseif (!preg_match("/\.sql$/", basename($file))) { |
| 53 | throw new tao_install_utils_SQLParsingException( |
| 54 | "File '${file}' is not a valid SQL file. Extension '.sql' not found." |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | $content = @file_get_contents($file); |
| 59 | if ($content !== false) { |
| 60 | $matches = []; |
| 61 | $functions = explode(';;', $content); |
| 62 | |
| 63 | |
| 64 | foreach ($functions as $f) { |
| 65 | $this->addStatement($f); |
| 66 | } |
| 67 | } else { |
| 68 | throw new tao_install_utils_SQLParsingException( |
| 69 | "SQL file '${file}' cannot be read. An unknown error occured while reading it." |
| 70 | ); |
| 71 | } |
| 72 | } |
| 73 | } |