| Code Coverage | ||||||||||
| Lines | Functions and Methods | Classes and Traits | ||||||||
| Total |  | 0.00% | 0 / 22 |  | 0.00% | 0 / 1 | CRAP |  | 0.00% | 0 / 1 | 
| tao_install_utils_PostgresProceduresParser |  | 0.00% | 0 / 22 |  | 0.00% | 0 / 1 | 56 |  | 0.00% | 0 / 1 | 
| parse |  | 0.00% | 0 / 22 |  | 0.00% | 0 / 1 | 56 | |||
| 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 | class tao_install_utils_PostgresProceduresParser extends tao_install_utils_SQLParser | 
| 36 | { | 
| 37 | /** | 
| 38 | * Parse a SQL file containing mySQL compliant Procedures or Functions. | 
| 39 | * @return void | 
| 40 | * @throws tao_install_utils_SQLParsingException | 
| 41 | */ | 
| 42 | public function parse() | 
| 43 | { | 
| 44 | $this->setStatements([]); | 
| 45 | $file = $this->getFile(); | 
| 46 | |
| 47 | if (!file_exists($file)) { | 
| 48 | throw new tao_install_utils_SQLParsingException("SQL file '${file}' does not exist."); | 
| 49 | } elseif (!is_readable($file)) { | 
| 50 | throw new tao_install_utils_SQLParsingException("SQL file '${file}' is not readable."); | 
| 51 | } elseif (!preg_match("/\.sql$/", basename($file))) { | 
| 52 | throw new tao_install_utils_SQLParsingException( | 
| 53 | "File '${file}' is not a valid SQL file. Extension '.sql' not found." | 
| 54 | ); | 
| 55 | } | 
| 56 | |
| 57 | $content = @file_get_contents($file); | 
| 58 | if ($content !== false) { | 
| 59 | $matches = []; | 
| 60 | $patterns = [ | 
| 61 | 'CREATE\s*(?:OR\s+REPLACE){0,1}\s*FUNCTION\s+(?:.*\s)*?END\s*.*\s*;(?:\s*.*?\s*LANGUAGE\s+.*\s*;)*' | 
| 62 | ]; | 
| 63 | |
| 64 | if (preg_match_all('/' . implode($patterns, '|') . '/i', $content, $matches)) { | 
| 65 | foreach ($matches[0] as $match) { | 
| 66 | $this->addStatement($match); | 
| 67 | } | 
| 68 | } | 
| 69 | } else { | 
| 70 | throw new tao_install_utils_SQLParsingException( | 
| 71 | "SQL file '${file}' cannot be read. An unknown error occured while reading it." | 
| 72 | ); | 
| 73 | } | 
| 74 | } | 
| 75 | } |