| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZDBPackageHandler class 4 // 5 // Created on: <23-Jul-2003 16:11:42 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezdbpackagehandler.php 30 */ 31 32 /*! 33 \class eZDBPackageHandler ezdbpackagehandler.php 34 \brief Handles content classes in the package system 35 36 */ 37 38 include_once ( 'lib/ezxml/classes/ezxml.php' ); 39 include_once ( 'kernel/classes/ezpackagehandler.php' ); 40 41 class eZDBPackageHandler extends eZPackageHandler 42 { 43 /*! 44 Constructor 45 */ 46 function eZDBPackageHandler() 47 { 48 $this->eZPackageHandler( 'ezdb' ); 49 } 50 51 /*! 52 Installs the package type 53 */ 54 function install( &$package, $installType, $parameters, 55 $name, $os, $filename, $subdirectory, 56 &$content, $installParameters ) 57 { 58 if ( $installType == 'sql' ) 59 { 60 $path = $package->path(); 61 $databaseType = false; 62 if ( isset( $parameters['database-type'] ) ) 63 $databaseType = $parameters['database-type']; 64 $path .= '/' . eZDBPackageHandler::sqlDirectory(); 65 if ( $databaseType ) 66 $path .= '/' . $databaseType; 67 if ( file_exists( $path ) ) 68 { 69 $db =& eZDB::instance(); 70 $canInsert = true; 71 if ( $databaseType and 72 $databaseType != $db->databaseName() ) 73 $canInsert = false; 74 if ( $canInsert ) 75 { 76 eZDebug::writeDebug( "Installing SQL file $path/$filename" ); 77 $db->insertFile( $path, $filename, false ); 78 return true; 79 } 80 else 81 eZDebug::writeDebug( "Skipping SQL file $path/$filename" ); 82 } 83 else 84 eZDebug::writeError( "Could not find SQL file $path/$filename" ); 85 } 86 return false; 87 } 88 89 /*! 90 \reimp 91 */ 92 function add( $packageType, &$package, &$cli, $parameters ) 93 { 94 if ( isset( $parameters['sql-file-list'] ) ) 95 { 96 foreach ( $parameters['sql-file-list'] as $fileItem ) 97 { 98 $package->appendInstall( 'sql', false, false, true, 99 $fileItem['file'], false, 100 array( 'path' => $fileItem['path'], 101 'database-type' => $fileItem['database_type'], 102 'copy-file' => true ) ); 103 if ( $fileItem['database_type'] ) 104 $package->appendDependency( 'requires', 105 array( 'type' => 'ezdb', 106 'name' => $fileItem['database_type'], 107 'value' => false ) ); 108 $noticeText = "Adding " . $cli->stylize( 'mark', "sql" ) . " file " . $cli->stylize( 'file', $fileItem['path'] ); 109 if ( $fileItem['database_type'] ) 110 $noticeText .= " for database " . $cli->stylize( 'emphasize', $fileItem['database_type'] ); 111 $cli->notice( $noticeText ); 112 } 113 } 114 } 115 116 function handleAddParameters( $packageType, &$package, &$cli, $arguments ) 117 { 118 return $this->handleParameters( $packageType, $package, $cli, 'add', $arguments ); 119 } 120 121 function handleParameters( $packageType, &$package, &$cli, $type, $arguments ) 122 { 123 $sqlFileList = array(); 124 $currentType = false; 125 $currentDatabaseType = false; 126 if ( $packageType == 'sql' ) 127 { 128 $currentType = 'sql'; 129 } 130 for ( $i = 0; $i < count( $arguments ); ++$i ) 131 { 132 $argument = $arguments[$i]; 133 if ( $argument[0] == '-' ) 134 { 135 if ( strlen( $argument ) > 1 and 136 $argument[1] == '-' ) 137 { 138 } 139 else 140 { 141 $flag = substr( $argument, 1, 1 ); 142 if ( $flag == 'd' ) 143 { 144 if ( strlen( $argument ) > 2 ) 145 { 146 $data = substr( $argument, 2 ); 147 } 148 else 149 { 150 $data = $arguments[$i+1]; 151 ++$i; 152 } 153 if ( $flag == 'd' ) 154 { 155 $currentDatabaseType = $data; 156 } 157 } 158 } 159 } 160 else 161 { 162 if ( $currentType == 'sql' ) 163 { 164 $sqlFile = $argument; 165 $databaseType = $currentDatabaseType; 166 $realFilePath = $this->sqlFileExists( $sqlFile, $databaseType, 167 $triedFiles ); 168 if ( !$realFilePath ) 169 { 170 $cli->error( "SQL file " . $cli->style( 'file' ) . $sqlFile . $cli->style( 'file-end' ) . " does not exist\n" . 171 "The following files were searched for:\n" . 172 implode( "\n", $triedFiles ) ); 173 return false; 174 } 175 $fileList[] = array( 'file' => $sqlFile, 176 'database_type' => $databaseType, 177 'path' => $realFilePath ); 178 } 179 } 180 } 181 if ( count( $fileList ) == 0 ) 182 { 183 $cli->error( "No files were added" ); 184 return false; 185 } 186 return array( 'sql-file-list' => $fileList ); 187 } 188 189 function sqlFileExists( &$sqlFile, &$databaseType, 190 &$triedFiles ) 191 { 192 $triedFiles = array(); 193 if ( file_exists( $sqlFile ) ) 194 { 195 $filePath = $sqlFile; 196 if ( preg_match( '#^.+/([^/]+$)#', $sqlFile, $matches ) ) 197 $sqlFile = $matches[1]; 198 return $filePath; 199 } 200 $filePath = 'kernel/sql/' . $databaseType . '/' . $sqlFile; 201 if ( file_exists( $filePath ) ) 202 return $filePath; 203 $triedFiles[] = $filePath; 204 $filePath = 'kernel/sql/' . $databaseType . '/' . $sqlFile . '.sql'; 205 if ( file_exists( $filePath ) ) 206 { 207 $sqlFile .= '.sql'; 208 return $filePath; 209 } 210 $triedFiles[] = $filePath; 211 return false; 212 } 213 214 function sqlDirectory() 215 { 216 return 'sql'; 217 } 218 219 /*! 220 \reimp 221 */ 222 function createInstallNode( &$package, $export, &$installNode, $installItem, $installType ) 223 { 224 if ( $installNode->attributeValue( 'type' ) == 'sql' ) 225 { 226 if ( !$export ) 227 $installNode->appendAttribute( eZDOMDocument::createAttributeNode( 'original-path', 228 $installItem['path'] ) ); 229 $installNode->appendAttribute( eZDOMDocument::createAttributeNode( 'database-type', 230 $installItem['database-type'] ) ); 231 if ( $export ) 232 { 233 $originalPath = $package->path() . '/' . eZDBPackageHandler::sqlDirectory(); 234 if ( $installItem['database-type'] ) 235 $originalPath .= '/' . $installItem['database-type']; 236 $originalPath .= '/' . $installItem['filename']; 237 $exportPath = $export['path']; 238 $installDirectory = $exportPath . '/' . eZDBPackageHandler::sqlDirectory(); 239 if ( $installItem['database-type'] ) 240 $installDirectory .= '/' . $installItem['database-type']; 241 if ( !file_exists( $installDirectory ) ) 242 eZDir::mkdir( $installDirectory, eZDir::directoryPermission(), true ); 243 eZFileHandler::copy( $originalPath, $installDirectory . '/' . $installItem['filename'] ); 244 } 245 else if ( isset( $installItem['copy-file'] ) and $installItem['copy-file'] ) 246 { 247 $originalPath = $installItem['path']; 248 $installDirectory = $package->path() . '/' . eZDBPackageHandler::sqlDirectory(); 249 if ( $installItem['database-type'] ) 250 $installDirectory .= '/' . $installItem['database-type']; 251 if ( !file_exists( $installDirectory ) ) 252 eZDir::mkdir( $installDirectory, eZDir::directoryPermission(), true ); 253 eZFileHandler::copy( $originalPath, $installDirectory . '/' . $installItem['filename'] ); 254 } 255 } 256 } 257 258 /*! 259 \reimp 260 */ 261 function parseInstallNode( &$package, &$installNode, &$installParameters, $isInstall ) 262 { 263 if ( $installNode->attributeValue( 'type' ) == 'sql' ) 264 { 265 $installParameters['path'] = $installNode->attributeValue( 'original-path' ); 266 $installParameters['database-type'] = $installNode->attributeValue( 'database-type' ); 267 } 268 } 269 } 270 271 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |