[!!!][TASK] Rewrite install tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Database / PdoHelper.php
1 <?php
2 namespace TYPO3\CMS\Core\Database;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * A helper class for handling PDO databases
31 * Backport of FLOW3 class PdoHelper, last synced version: 3528
32 *
33 * @author Karsten Dambekalns <karsten@typo3.org>
34 */
35 class PdoHelper {
36
37 /**
38 * Pumps the SQL into the database. Use for DDL only.
39 *
40 * Important: key definitions with length specifiers (needed for MySQL) must
41 * be given as "field"(xyz) - no space between double quote and parenthesis -
42 * so they can be removed automatically.
43 *
44 * @param PDO $databaseHandle
45 * @param string $pdoDriver
46 * @param string $pathAndFilename
47 * @return void
48 * @author Karsten Dambekalns <karsten@typo3.org>
49 */
50 static public function importSql(\PDO $databaseHandle, $pdoDriver, $pathAndFilename) {
51 $sql = file($pathAndFilename, FILE_IGNORE_NEW_LINES & FILE_SKIP_EMPTY_LINES);
52 // Remove MySQL style key length delimiters (yuck!) if we are not setting up a MySQL db
53 if (substr($pdoDriver, 0, 5) !== 'mysql') {
54 $sql = preg_replace('/"\\([0-9]+\\)/', '"', $sql);
55 }
56 $statement = '';
57 foreach ($sql as $line) {
58 $statement .= ' ' . trim($line);
59 if (substr($statement, -1) === ';') {
60 $databaseHandle->exec($statement);
61 $statement = '';
62 }
63 }
64 }
65
66 }
67
68
69 ?>