00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 require_once( 'lib/ezutils/classes/ezdebugsetting.php' );
00035 require_once( 'lib/ezutils/classes/ezdebug.php' );
00036
00037 class eZDBFileHandler
00038 {
00039
00040
00041
00042
00043
00044 function eZDBFileHandler( $filePath = false )
00045 {
00046 eZDebugSetting::writeDebug( 'kernel-clustering', "db::ctor( '$filePath' )" );
00047
00048
00049 if ( !isset( $GLOBALS['eZDBFileHandler_chosen_backend_class'] ) )
00050 {
00051 require_once( 'lib/ezutils/classes/ezini.php' );
00052 $fileINI = eZINI::instance( 'file.ini' );
00053 $backendName = 'mysql';
00054 if ( $fileINI->hasVariable( 'ClusteringSettings', 'DBBackend' ) )
00055 $backendName = $fileINI->variable( 'ClusteringSettings', 'DBBackend' );
00056
00057 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00058 $searchPathArray = eZClusterFileHandler::searchPathArray();
00059
00060 foreach ( $searchPathArray as $searchPath )
00061 {
00062 $includeFileName = "$searchPath/dbbackends/$backendName.php";
00063 if ( is_readable( $includeFileName ) )
00064 {
00065 include_once( $includeFileName );
00066 $backendClassName = "eZDBFileHandler${backendName}Backend";
00067 $GLOBALS['eZDBFileHandler_chosen_backend_class'] = $backendClassName;
00068 }
00069 }
00070
00071 if ( !isset( $GLOBALS['eZDBFileHandler_chosen_backend_class'] ) )
00072 {
00073 eZDebug::writeError( "Cannot find ezdb cluster file backend: '$backendName'" );
00074 return;
00075 }
00076 }
00077
00078 $backendClassName = $GLOBALS['eZDBFileHandler_chosen_backend_class'];
00079 $this->backend = new $backendClassName;
00080 $this->backend->_connect();
00081 $this->metaData['name'] = $filePath;
00082
00083 $this->loadMetaData();
00084 }
00085
00086
00087
00088
00089
00090
00091
00092 function loadMetaData( $force = false )
00093 {
00094
00095 if ( $this->metaData['name'] !== false )
00096 {
00097 $metaData = $this->backend->_fetchMetadata( $this->metaData['name'] );
00098 if ( $metaData )
00099 $this->metaData = $metaData;
00100 }
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110 function fileStore( $filePath, $scope = false, $delete = false, $datatype = false )
00111 {
00112 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileStore( '$filePath' )" );
00113
00114 if ( $scope === false )
00115 $scope = 'UNKNOWN_SCOPE';
00116
00117 if ( $datatype === false )
00118 $datatype = 'misc';
00119
00120 $this->backend->_store( $filePath, $datatype, $scope );
00121
00122 if ( $delete )
00123 @unlink( $filePath );
00124 }
00125
00126
00127
00128
00129
00130
00131
00132 function fileStoreContents( $filePath, $contents, $scope = false, $datatype = false )
00133 {
00134 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileStoreContents( '$filePath' )" );
00135
00136 if ( $scope === false )
00137 $scope = 'UNKNOWN_SCOPE';
00138
00139 if ( $datatype === false )
00140 $datatype = 'misc';
00141
00142 $this->backend->_storeContents( $filePath, $contents, $scope, $datatype );
00143 }
00144
00145
00146
00147
00148
00149
00150 function storeContents( $contents, $scope = false, $datatype = false )
00151 {
00152 if ( $scope === false )
00153 $scope = 'UNKNOWN_SCOPE';
00154
00155 if ( $datatype === false )
00156 $datatype = 'misc';
00157
00158 $filePath = $this->metaData['name'];
00159 eZDebugSetting::writeDebug( 'kernel-clustering', "db::storeContents( '$filePath' )" );
00160 $this->backend->_storeContents( $filePath, $contents, $scope, $datatype );
00161 }
00162
00163
00164
00165
00166
00167
00168
00169 function fileFetch( $filePath )
00170 {
00171 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileFetch( '$filePath' )" );
00172
00173 return $this->backend->_fetch( $filePath );
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183 function fetchUnique( )
00184 {
00185 $filePath = $this->metaData['name'];
00186 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fetchUnique( '$filePath' )" );
00187
00188 $fetchWithUniqueName = true;
00189 $fetchedFilePath = $this->backend->_fetch( $filePath, $fetchWithUniqueName );
00190 $this->metaData['unique_name'] = $fetchedFilePath;
00191 return $fetchedFilePath;
00192 }
00193
00194
00195
00196
00197
00198
00199 function fetch()
00200 {
00201 $filePath = $this->metaData['name'];
00202 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fetch( '$filePath' )" );
00203 $this->backend->_fetch( $filePath );
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213 function fileFetchContents( $filePath )
00214 {
00215 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileFetchContents( '$filePath' )" );
00216
00217 $contents = $this->backend->_fetchContents( $filePath );
00218 return $contents;
00219 }
00220
00221
00222
00223
00224
00225
00226
00227 function fetchContents()
00228 {
00229 $filePath = $this->metaData['name'];
00230 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileFetchContents( '$filePath' )" );
00231 $contents = $this->backend->_fetchContents( $filePath );
00232 return $contents;
00233 }
00234
00235
00236
00237
00238
00239
00240 function stat()
00241 {
00242 eZDebugSetting::writeDebug( 'kernel-clustering', "db::stat()" );
00243 return $this->metaData;
00244 }
00245
00246
00247
00248
00249
00250
00251 function size()
00252 {
00253 eZDebugSetting::writeDebug( 'kernel-clustering', "db::size()" );
00254
00255 return isset( $this->metaData['size'] ) ? $this->metaData['size'] : null;
00256 }
00257
00258
00259
00260
00261
00262
00263 function mtime()
00264 {
00265 eZDebugSetting::writeDebug( 'kernel-clustering', "db::mtime()" );
00266
00267 return isset( $this->metaData['mtime'] ) ? $this->metaData['mtime'] : null;
00268 }
00269
00270
00271
00272
00273
00274
00275 function name()
00276 {
00277 eZDebugSetting::writeDebug( 'kernel-clustering', "db::name()" );
00278
00279 return isset( $this->metaData['name'] ) ? $this->metaData['name'] : null;
00280 }
00281
00282
00283
00284
00285
00286
00287 function fileDeleteByRegex( $dir, $fileRegex )
00288 {
00289 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileDeleteByRegex( '$dir', '$fileRegex' )" );
00290
00291 $regex = '^' . ( $dir ? $dir . '/' : '' ) . $fileRegex;
00292 $this->backend->_deleteByRegex( $regex );
00293 }
00294
00295
00296
00297
00298
00299
00300 function fileDeleteByWildcard( $wildcard )
00301 {
00302 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileDeleteByWildcard( '$wildcard' )" );
00303
00304 $this->backend->_deleteByWildcard( $wildcard );
00305 }
00306
00307
00308
00309
00310
00311 function fileDeleteByDirList( $dirList, $commonPath, $commonSuffix )
00312 {
00313 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileDeleteByDirList( '$dirList', '$commonPath', '$commonSuffix' )" );
00314
00315 $this->backend->_deleteByDirList( $dirList, $commonPath, $commonSuffix );
00316 }
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326 function fileDelete( $path )
00327 {
00328 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileDelete( '$path' )" );
00329
00330 $this->backend->_delete( $path );
00331 $this->backend->_deleteByLike( $path . '/%' );
00332 }
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 function delete()
00343 {
00344 $path = $this->metaData['name'];
00345 eZDebugSetting::writeDebug( 'kernel-clustering', "db::delete( '$path' )" );
00346
00347 $this->backend->_delete( $path );
00348 $this->backend->_deleteByRegex( $path . '/.+$' );
00349
00350
00351 }
00352
00353
00354
00355
00356
00357
00358
00359 function fileDeleteLocal( $path )
00360 {
00361 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileDeleteLocal( '$path' )" );
00362
00363 @unlink( $path );
00364 }
00365
00366
00367
00368
00369
00370
00371 function deleteLocal()
00372 {
00373 $path = $this->metaData['name'];
00374 eZDebugSetting::writeDebug( 'kernel-clustering', "db::deleteLocal( '$path' )" );
00375 @unlink( $path );
00376 }
00377
00378
00379
00380
00381
00382
00383
00384 function fileExists( $path )
00385 {
00386 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileExists( '$path' )" );
00387
00388 $rc = $this->backend->_exists( $path );
00389 return $rc;
00390 }
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400 function exists()
00401 {
00402 $path = $this->metaData['name'];
00403 eZDebugSetting::writeDebug( 'kernel-clustering', "db::exists( '$path' )" );
00404 $rc = $this->backend->_exists( $path );
00405 return $rc;
00406 }
00407
00408
00409
00410
00411
00412
00413 function passthrough()
00414 {
00415 $path = $this->metaData['name'];
00416 eZDebugSetting::writeDebug( 'kernel-clustering', "db::passthrough( '$path' )" );
00417 $size = $this->metaData['size'];
00418 $mimeType = $this->metaData['datatype'];
00419 $mtime = $this->metaData['mtime'];
00420 $mdate = gmdate( 'D, d M Y H:i:s T', $mtime );
00421
00422 header( "Content-Length: $size" );
00423 header( "Content-Type: $mimeType" );
00424 header( "Last-Modified: $mdate GMT" );
00425 header( "Expires: ". gmdate('D, d M Y H:i:s', time() + 6000) . 'GMT');
00426 header( "Connection: close" );
00427 header( "X-Powered-By: eZ publish" );
00428 header( "Accept-Ranges: bytes" );
00429
00430 $this->backend->_passThrough( $path );
00431 }
00432
00433
00434
00435
00436
00437
00438
00439 function fileCopy( $srcPath, $dstPath )
00440 {
00441 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileCopy( '$srcPath', '$dstPath' )" );
00442
00443 $this->backend->_copy( $srcPath, $dstPath );
00444 }
00445
00446
00447
00448
00449
00450
00451
00452 function fileLinkCopy( $srcPath, $dstPath, $symLink )
00453 {
00454 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileLinkCopy( '$srcPath', '$dstPath' )" );
00455
00456 $this->backend->_linkCopy( $srcPath, $dstPath );
00457 }
00458
00459
00460
00461
00462
00463
00464
00465 function fileMove( $srcPath, $dstPath )
00466 {
00467 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileMove( '$srcPath', '$dstPath' )" );
00468
00469 $this->backend->_rename( $srcPath, $dstPath );
00470
00471
00472 }
00473
00474
00475
00476
00477
00478
00479 function move( $dstPath )
00480 {
00481 $srcPath = $this->metaData['name'];
00482
00483 eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileMove( '$srcPath', '$dstPath' )" );
00484
00485 $this->backend->_rename( $srcPath, $dstPath );
00486
00487
00488 }
00489
00490
00491
00492
00493
00494
00495 function getFileList( $skipBinaryFiles = false, $skipImages = false )
00496 {
00497 eZDebugSetting::writeDebug( 'kernel-clustering',
00498 sprintf( "db::getFileList( %d, %d )",
00499 (int) $skipBinaryFiles, (int) $skipImages ) );
00500 return $this->backend->_getFileList( $skipBinaryFiles, $skipImages );
00501 }
00502 }
00503
00504 ?>