Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezdbpackagehandler.php
Go to the documentation of this file.
1 <?php
17 class eZDBPackageHandler extends eZPackageHandler
18 {
19 public function __construct()
20 {
21 parent::__construct( 'ezdb' );
22 }
23
27 function install( $package, $installType, $parameters,
28 $name, $os, $filename, $subdirectory,
29 $content, &$installParameters,
30 &$installData )
31 {
32 $path = $package->path();
33 $databaseType = false;
34 if ( isset( $parameters['database-type'] ) )
35 {
36 $databaseType = $parameters['database-type'];
37 }
38 $path .= '/' . eZDBPackageHandler::sqlDirectory();
39 if ( $databaseType )
40 {
41 $path .= '/' . $databaseType;
42 }
43
44 if ( file_exists( $path ) )
45 {
46 $db = eZDB::instance();
47 $canInsert = true;
48 if ( $databaseType and
49 $databaseType != $db->databaseName() )
50 {
51 $canInsert = false;
52 }
53
54 if ( $canInsert )
55 {
56 eZDebug::writeDebug( "Installing SQL file $path/$filename" );
57 $db->insertFile( $path, $filename, false );
58 return true;
59 }
60 else
61 {
62 eZDebug::writeDebug( "Skipping SQL file $path/$filename" );
63 }
64 }
65 else
66 {
67 eZDebug::writeError( "Could not find SQL file $path/$filename" );
68 }
69 return false;
70 }
71
72 function add( $packageType, $package, $cli, $parameters )
73 {
74 if ( isset( $parameters['sql-file-list'] ) )
75 {
76 foreach ( $parameters['sql-file-list'] as $fileItem )
77 {
78 $package->appendInstall( 'sql', false, false, true,
79 $fileItem['file'], false,
80 array( 'path' => $fileItem['path'],
81 'database-type' => $fileItem['database_type'],
82 'copy-file' => true ) );
83 if ( $fileItem['database_type'] )
84 $package->appendDependency( 'requires',
85 array( 'type' => 'ezdb',
86 'name' => $fileItem['database_type'],
87 'value' => false ) );
88 $noticeText = "Adding " . $cli->stylize( 'mark', "sql" ) . " file " . $cli->stylize( 'file', $fileItem['path'] );
89 if ( $fileItem['database_type'] )
90 $noticeText .= " for database " . $cli->stylize( 'emphasize', $fileItem['database_type'] );
91 $cli->notice( $noticeText );
92 }
93 }
94 }
95
96 function handleAddParameters( $packageType, $package, $cli, $arguments )
97 {
98 return $this->handleParameters( $packageType, $package, $cli, 'add', $arguments );
99 }
100
101 function handleParameters( $packageType, $package, $cli, $type, $arguments )
102 {
103 $sqlFileList = array();
104 $currentDatabaseType = false;
105
106 for ( $i = 0; $i < count( $arguments ); ++$i )
107 {
108 $argument = $arguments[$i];
109 if ( $argument[0] == '-' )
110 {
111 if ( strlen( $argument ) > 1 and
112 $argument[1] == '-' )
113 {
114 }
115 else
116 {
117 $flag = substr( $argument, 1, 1 );
118 if ( $flag == 'd' )
119 {
120 if ( strlen( $argument ) > 2 )
121 {
122 $data = substr( $argument, 2 );
123 }
124 else
125 {
126 $data = $arguments[$i+1];
127 ++$i;
128 }
129 if ( $flag == 'd' )
130 {
131 $currentDatabaseType = $data;
132 }
133 }
134 }
135 }
136 else
137 {
138 $sqlFile = $argument;
139 $databaseType = $currentDatabaseType;
140 $realFilePath = $this->sqlFileExists( $sqlFile, $databaseType,
141 $triedFiles );
142 if ( !$realFilePath )
143 {
144 $cli->error( "SQL file " . $cli->style( 'file' ) . $sqlFile . $cli->style( 'file-end' ) . " does not exist\n" .
145 "The following files were searched for:\n" .
146 implode( "\n", $triedFiles ) );
147 return false;
148 }
149 $fileList[] = array( 'file' => $sqlFile,
150 'database_type' => $databaseType,
151 'path' => $realFilePath );
152 }
153 }
154 if ( count( $fileList ) == 0 )
155 {
156 $cli->error( "No files were added" );
157 return false;
158 }
159 return array( 'sql-file-list' => $fileList );
160 }
161
162 function sqlFileExists( &$sqlFile, &$databaseType,
163 &$triedFiles )
164 {
165 $triedFiles = array();
166 if ( file_exists( $sqlFile ) )
167 {
168 $filePath = $sqlFile;
169 if ( preg_match( '#^.+/([^/]+$)#', $sqlFile, $matches ) )
170 $sqlFile = $matches[1];
171 return $filePath;
172 }
173 $filePath = 'kernel/sql/' . $databaseType . '/' . $sqlFile;
174 if ( file_exists( $filePath ) )
175 return $filePath;
176 $triedFiles[] = $filePath;
177 $filePath = 'kernel/sql/' . $databaseType . '/' . $sqlFile . '.sql';
178 if ( file_exists( $filePath ) )
179 {
180 $sqlFile .= '.sql';
181 return $filePath;
182 }
183 $triedFiles[] = $filePath;
184 return false;
185 }
186
187 function sqlDirectory()
188 {
189 return 'sql';
190 }
191
192 function createInstallNode( $package, $installNode, $installItem, $installType )
193 {
194 $installNode->setAttribute( 'original-path', $installItem['path'] );
195 $installNode->setAttribute( 'database-type', $installItem['database-type'] );
196
197 $originalPath = $installItem['path'];
198 $installDirectory = $package->path() . '/' . eZDBPackageHandler::sqlDirectory();
199 if ( $installItem['database-type'] )
200 $installDirectory .= '/' . $installItem['database-type'];
201 if ( !file_exists( $installDirectory ) )
202 eZDir::mkdir( $installDirectory, false, true );
203 eZFileHandler::copy( $originalPath, $installDirectory . '/' . $installItem['filename'] );
204 }
205
206 function parseInstallNode( $package, $installNode, &$installParameters, $isInstall )
207 {
208 $installParameters['path'] = $installNode->getAttribute( 'original-path' );
209 $installParameters['database-type'] = $installNode->getAttribute( 'database-type' );
210 }
211 }
212
213 ?>
eZDBPackageHandler
Handles SQL files in the package system.
Definition: ezdbpackagehandler.php:18
eZDBPackageHandler\handleAddParameters
handleAddParameters( $packageType, $package, $cli, $arguments)
Definition: ezdbpackagehandler.php:96
eZDBPackageHandler\sqlFileExists
sqlFileExists(&$sqlFile, &$databaseType, &$triedFiles)
Definition: ezdbpackagehandler.php:162
eZDBPackageHandler\add
add( $packageType, $package, $cli, $parameters)
Definition: ezdbpackagehandler.php:72
eZDBPackageHandler\handleParameters
handleParameters( $packageType, $package, $cli, $type, $arguments)
Definition: ezdbpackagehandler.php:101
eZDBPackageHandler\__construct
__construct()
Definition: ezdbpackagehandler.php:19
eZDBPackageHandler\parseInstallNode
parseInstallNode( $package, $installNode, &$installParameters, $isInstall)
Definition: ezdbpackagehandler.php:206
eZDBPackageHandler\createInstallNode
createInstallNode( $package, $installNode, $installItem, $installType)
Definition: ezdbpackagehandler.php:192
eZDBPackageHandler\install
install( $package, $installType, $parameters, $name, $os, $filename, $subdirectory, $content, &$installParameters, &$installData)
Definition: ezdbpackagehandler.php:27
eZDBPackageHandler\sqlDirectory
sqlDirectory()
Definition: ezdbpackagehandler.php:187
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeDebug
static writeDebug( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:588
eZDir\mkdir
static mkdir( $dir, $perm=false, $recursive=false)
Definition: ezdir.php:73
eZFileHandler\copy
static copy( $sourceFilename, $destinationFilename)
Definition: ezfilehandler.php:356
eZPackageHandler
The class eZPackageHandler does.
Definition: ezpackagehandler.php:18
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.