public function tearDown() { // restore the previous file handler if ($this->previousFileHandler !== null) { $fileINI = eZINI::instance('file.ini'); $fileINI->setVariable('ClusteringSettings', 'FileHandler', $this->previousFileHandler); $this->previousFileHandler = null; eZClusterFileHandler::resetHandler(); } if ($this->haveToRemoveDFSPath) { eZDir::recursiveDelete($this->DFSPath); } parent::tearDown(); }
/** * Clear global ini cache */ static function clearGlobalINICache($cacheItem) { eZDir::recursiveDelete($cacheItem['path']); }
{ $notRemoved[] = array( 'filename' => $fileName ); } } if ( $overrideINI->save( "siteaccess/$siteAccess/override.ini.append" ) == false ) { $overrideINISaveFailed = true; } // Expire content view cache eZContentCacheManager::clearAllContentCache(); // Clear override cache $cachedDir = eZSys::cacheDirectory(); $cachedDir .= "/override/"; eZDir::recursiveDelete( $cachedDir ); } } $overrideArray = eZTemplateDesignResource::overrideArray( $siteAccess ); $templateSettings = false; if ( isset( $overrideArray[$template] ) ) { $templateSettings = $overrideArray[$template]; } if ( !isset( $templateSettings['custom_match'] ) ) $templateSettings['custom_match'] = 0; $tpl->setVariable( 'template_settings', $templateSettings );
public function tearDown() { ezpINIHelper::restoreINISettings(); if (isset($GLOBALS['eZClusterFileHandler_chosen_handler'])) { unset($GLOBALS['eZClusterFileHandler_chosen_handler']); } if ($this->haveToRemoveDFSPath) { eZDir::recursiveDelete(self::$DFSPath); } parent::tearDown(); }
function downloadPackages($packageList, $packageURL, $packageDir, $packageRepository) { global $cli; showMessage2("Configuring..."); if (!is_array($packageList) || count($packageList) == 0) { showError("Package list is empty. Aborting..."); } // 1. check if packages specified in $packageList exist in $packageRepository(means already downloaded and imported). // if yes - ask user to do download or not. If not - go out foreach (array_keys($packageList) as $k) { $packageName = $packageList[$k]; $package = eZPackage::fetch($packageName); if (is_object($package)) { global $autoMode; if ($autoMode == 'on') { $action = 'y'; } else { $action = getUserInput("Package '{$packageName}' already imported. Import it anyway? [y/n]: "); } if (strpos($action, 'n') === 0) { unset($packageList[$k]); } else { eZDir::recursiveDelete(eZPackage::repositoryPath() . "/{$packageRepository}/{$packageName}"); } } } if (count($packageList) == 0) { // all packages are imported. return true; } // 2. check $packgesList exists in $packageDir(means packages downloaded but not imported) // if yes - ask user to import or not. If not - go out if (!checkDir($packageDir)) { return false; } $downloadPackageList = array(); foreach ($packageList as $packageName) { if (file_exists("{$packageDir}/{$packageName}.ezpkg")) { global $autoMode; if ($autoMode == 'on') { $action = 'y'; } else { $action = getUserInput("Package '{$packageName}' already downloaded. Download it anyway? [y/n]: "); } if (strpos($action, 'n') === 0) { continue; } } $downloadPackageList[] = $packageName; } // // download // showMessage2("Downloading..."); if (count($downloadPackageList) > 0) { // TODO: using 'eZStepSiteTypes' is hack. // need to exclude 'downloadFile' from that class. $tpl = false; $http = false; $ini = false; $persistenceList = false; $downloader = new eZStepSiteTypes($tpl, $http, $ini, $persistenceList); foreach ($downloadPackageList as $packageName) { showMessage("{$packageName}"); $archiveName = $downloader->downloadFile("{$packageURL}/{$packageName}.ezpkg", $packageDir); if ($archiveName === false) { showError("download error - " . $downloader->ErrorMsg); } } } // // import // showMessage2("Importing..."); foreach ($packageList as $packageName) { showMessage("{$packageName}"); $package = eZPackage::import("{$packageDir}/{$packageName}.ezpkg", $packageName, false, $packageRepository); if (!is_object($package)) { showError("Faild to import '{$packageName}' package: err = {$package}"); } } return true; }
public function testRemoveWithCheckNotExisting() { $this->assertFalse(eZDir::recursiveDelete($this->rootDir . 'doesNotExist', true)); }
public function setUp() { eZDir::recursiveDelete(eZINI::instance()->variable('FileSettings', 'VarDir')); eZContentLanguage::expireCache(); }
/** * Purges local and remote file data for current file path. * * Can be given a file or a folder. In order to clear a folder, do NOT add * a trailing / at the end of the file's path: path/to/file instead of * path/to/file/. * * By default, only expired files will be removed (ezdfsfile.expired = 1). * If you specify an $expiry time, it will replace the expired test and * only purge files older than the given expiry timestamp. * * @param callback $printCallback * Callback called after each delete iteration (@see $max) to print * out a report of the deleted files. This callback expects two * parameters, $file (delete pattern used to perform deletion) and * $count (number of deleted items) * @param int $microsleep * Wait interval before each purge batch of $max items * @param int $max * Maximum number of items to delete in one batch (default: 100) * @param int $expiry * If specificed, only files older than this date will be purged * @return void */ function purge($printCallback = false, $microsleep = false, $max = false, $expiry = false) { eZDebugSetting::writeDebug('kernel-clustering', "dfs::purge( '{$this->filePath}' )"); $file = $this->filePath; if ($max === false) { $max = 100; } $count = 0; /** * The loop starts without knowing how many files are to be deleted. * When _purgeByLike is called, it returns the number of affected rows. * If rows were affected, _purgeByLike will be called again */ do { // @todo this won't work on windows, make a wrapper that uses // either usleep or sleep depending on the OS if ($count > 0 && $microsleep) { usleep($microsleep); // Sleep a bit to make the database happier } $count = self::$dbbackend->_purgeByLike($file . "/%", true, $max, $expiry, 'purge'); self::$dbbackend->_purge($file, true, $expiry, 'purge'); if ($printCallback) { call_user_func_array($printCallback, array($file, $count)); } // @todo Compare $count to $max. If $count < $max, no more files are to // be purged, and we can exit the loop } while ($count > 0); // Remove local copies if (is_file($file)) { @unlink($file); } elseif (is_dir($file)) { eZDir::recursiveDelete($file); } eZClusterFileHandler::cleanupEmptyDirectories($file); }
/** * Removes a directory and all it's contents, recursively. * * @param string $dir Directory to remove * @param bool $rootCheck Check whether $dir is supposed to be contained in * eZ Publish root directory * @return bool True if the operation succeeded, false otherwise */ static function recursiveDelete($dir, $rootCheck = true) { // RecursiveDelete fails if ... // $dir is not a directory if (!is_dir($dir)) { eZDebug::writeError("The path: {$dir} is not a folder", __METHOD__); return false; } if ($rootCheck) { // rootCheck is enabled, check if $dir is part of authorized directories $allowedDirs = eZINI::instance()->variable('FileSettings', 'AllowedDeletionDirs'); // Also adding eZ Publish root dir. $rootDir = eZSys::rootDir() . DIRECTORY_SEPARATOR; array_unshift($allowedDirs, $rootDir); $dirRealPath = dirname(realpath($dir)) . DIRECTORY_SEPARATOR; $canDelete = false; foreach ($allowedDirs as $allowedDir) { if (strpos($dirRealPath, realpath($allowedDir)) === 0) { $canDelete = true; break; } } if (!$canDelete) { eZDebug::writeError("Recursive delete denied for '{$dir}' as its realpath '{$dirRealPath}' is outside eZ Publish root and not registered in AllowedDeletionDirs."); return false; } } // the directory cannot be opened if (!($handle = @opendir($dir))) { eZDebug::writeError("Cannot access folder:" . dirname($dir), __METHOD__); return false; } while (($file = readdir($handle)) !== false) { if ($file == "." || $file == "..") { continue; } if (is_dir($dir . '/' . $file)) { eZDir::recursiveDelete($dir . '/' . $file, false); } else { unlink($dir . '/' . $file); } } @closedir($handle); return rmdir($dir); }
function purge($printCallback = false, $microsleep = false, $max = false, $expiry = false) { $file = $this->filePath; if ($max === false) { $max = 100; } $count = 0; do { if ($count > 0 && $microsleep) { usleep($microsleep); } // Sleep a bit to make the database happier $count = $this->backend->_purgeByLike($file . "/%", true, $max, $expiry, 'purge'); $this->backend->_purge($file, true, $expiry, 'purge'); if ($printCallback) { call_user_func_array($printCallback, array($file, $count)); } } while ($count > 0); // Remove local copy if (is_file($file)) { @unlink($file); } else { if (is_dir($file)) { eZDir::recursiveDelete($file); } } }
/** * Removes icons for given application * @param string $appIdentifier Identifier of app * @param string $clusterIdentifier Identifier of cluster */ function removeIcons() { global $appIdentifier, $clusterIdentifier; $imageDirPath = eZDir::path( array( StaticData::directory(), $clusterIdentifier, 'apps', $appIdentifier ) ); eZDir::recursiveDelete($imageDirPath); }
public function tearDown() { ezpINIHelper::restoreINISettings(); eZClusterFileHandler::resetHandler(); if ($this->haveToRemoveDFSPath) { eZDir::recursiveDelete(self::$DFSPath); } parent::tearDown(); }
function purge( $printCallback = false, $microsleep = false, $max = false, $expiry = false ) { $file = $this->filePath; if ( $max === false ) $max = 100; $count = 0; do { if ( $count > 0 && $microsleep ) usleep( $microsleep ); // Sleep a bit to make the database happier $count = self::$dbbackend->_purgeByLike( $file . "/%", true, $max, $expiry, 'purge' ); self::$dbbackend->_purge( $file, true, $expiry, 'purge' ); if ( $printCallback ) call_user_func_array( $printCallback, array( $file, $count ) ); } while ( $count > 0 ); // Remove local copy if ( is_file( $file ) ) { @unlink( $file ); } else if ( is_dir( $file ) ) { eZDir::recursiveDelete( $file ); } eZClusterFileHandler::cleanupEmptyDirectories( $file ); }
/** * NOTE: What if other data is also in the db? Either we do not convert it and * have it most likely corrupted, or we convert it - and leave to the client * for the other apps to set up NLS_LANG correctly to keep working. * * We could use the csalter script iff we where sure that db version was > 9... * * Oracle 9 exp exports data using the DB charset * * From http://www.experts-exchange.com/Database/Oracle/Q_22836430.html May be the best procedure is the following one: On PROD Database: 1. export full=y rows=n file=export_db_structure.dmp 2. export full=y file=export_db_date.dmp On TEST Database: 1. create tablespaces with the same name on PROD 2. import full=y file=export_db_structure.dmp ignore=y Now we have users of PROD, on TEST database. SYSTEM user is not imported, because already exists. 3. import fromuser=user1,user2,user3 touser=user1,user2,user3 file=export_db_data.dmp ignore=y now we have user1..3 data on their tables... * Unfortunately even if we do that, Oracle will nto let us convert a db from * latin1 to utf8 charsets. The only way is to drop the db and creater it * from scratch. Since we have no clue about db storage, we will let the admin * take care of that part, and only do the export/import parts. * * @todo oracle servers might use UTF8 charset instead of AL32UTF8: check before executing! * * @todo using dbname as file name does not work with easy conection naming * * @todo log somewhere results of imp, exp commands for better understanding of errors */ function changeDBCharsetORACLE($charset, $collation) { global $db, $oracleDbaAccount, $oracleHome, $eZDir; //$db = eZDB::instance( false, array( 'user' => $oracleDbaAccount['user'], 'password' => $oracleDbaAccount['password'] ), true ); // since we are here, we should be connected with a dba account (extra conditions check did it) $oracleCharset = $db->arrayQuery("select value from nls_database_parameters where parameter = 'NLS_CHARACTERSET'"); $oracleCharset = $oracleCharset[0]['value']; //$oracleLocale = $db->arrayQuery("select language||'_'||territory as locale from (select value as language from nls_database_parameters where parameter = 'NLS_LANGUAGE'), (select value as territory from nls_database_parameters where parameter = 'NLS_TERRITORY')"); //$oracleLocale = $oracleLocale[0]['locale']; /*$users = $db->arrayQuery("select username from all_users where username not in ('SYS', 'SYSTEM')"); $oracleUsers = array(); foreach( $users as $row ) { $oracleUsers[] = $row['username']; }*/ if ($oracleCharset == 'AL32UTF8') { // lucky case: client was configued to use another charset, but db was internally utf8 already! showMessage3(" database charset is already UTF8: skipping."); } else { // get database name $dbName = $db->DB; //$dbversion = $db->databaseServerVersion(); // get connection params //$host = $db->Server; //$port = $db->Port; //$user = $db->User; //$pass = $db->Password; $connectionParams = $oracleDbaAccount['user'] . '/' . $oracleDbaAccount['password'] . "@{$dbName}"; // get temporary dir to store dumps $ini = eZINI::instance(); $dumpDir = $ini->variable('FileSettings', 'TemporaryDir') . basename(__FILE__, '.php'); $dumpFile1 = $dbName . "_structure_export.dmp"; $dumpPath1 = "{$dumpDir}/{$dumpFile1}"; $dumpFile2 = $dbName . "_full_export.dmp"; $dumpPath2 = "{$dumpDir}/{$dumpFile2}"; $commandPath = "{$dumpDir}/{$dbName}" . "_cmd.sql"; $logPath = "{$dumpDir}/{$dbName}" . "_cmd.log"; $users = implode(',', $oracleUsers); //$ora_charset = ""; // prepare utility commands $exe = eZSys::osType() == 'win32' ? '.exe' : ''; $exec = eZSys::osType() == 'win32' ? '' : './'; $expdb1 = "{$exec}exp{$exe} {$connectionParams} CONSISTENT=Y FULL=Y ROWS=N FILE={$dumpPath1}"; $expdb2 = "{$exec}exp{$exe} {$connectionParams} CONSISTENT=Y FULL=Y FILE={$dumpPath2}"; $impdb1 = "{$exec}imp{$exe} {$connectionParams} FULL=Y IGNORE=Y BUFFER=30960 FILE={$dumpPath1}"; $impdb2 = "{$exec}imp{$exe} {$connectionParams} FROMUSER={$users} TOUSER={$users} IGNORE=Y BUFFER=30960 FILE={$dumpPath2}"; /* $alterdb = "SET ECHO ON SPOOL $logPath; WHENEVER SQLERROR EXIT FAILURE; WHENEVER OSERROR EXIT FAILURE;"; if ( $dbversion['string'][0] == '8' ) { /// @todo: check if using oracle < 8.1.5: we have touse svrmgrl then, as sqlplus was not good enough yet $sqlplus = "{$exec}sqlplus{$exe} $connectionParams"; $alterdb .= " CONNECT $connectionParams AS SYSDBA"; } else { $sqlplus = "{$exec}sqlplus{$exe} -L $connectionParams as sysdba"; } //$dropdb = "dropdb $connectionParams"; //$createdb = "createdb $connectionParams"; foreach( $oracleUsers as $user ) { $alterdb .= " DROP USER $user CASCADE;"; } $alterdb .= " SHUTDOWN IMMEDIATE; STARTUP MOUNT; ALTER SYSTEM ENABLE RESTRICTED SESSION; ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0; ALTER SYSTEM SET AQ_TM_PROCESSES=0; ALTER DATABASE OPEN; ALTER DATABASE CHARACTER SET AL32UTF8; SHUTDOWN IMMEDIATE; -- or SHUTDOWN NORMAL; STARTUP; EXIT; "; */ // finalizing changes. Note that since we asked for admin connection before, // disconnecting and reconnecting, this is surely a NOOP //showMessage3( 'finalizing current changes' ); //$db->commit(); /// @todo add a database logfile switch or checkpoint here? it would be nice... // close current connection $db->close(); showMessage3(' sleeping..'); sleep(5); // dump db showMessage3(" taking the db dump, tmp storage is '{$dumpPath1}', '{$dumpPath2}'"); eZDir::mkdir($dumpDir, false, true); chdir($oracleHome . '/bin'); eZExecuteShellCommand($expdb1, "failed to dump db schema. tried command '{$expdb1}'", true, true); eZExecuteShellCommand($expdb2, "failed to dump db data. tried command '{$expdb2}'", true, true); chdir($eZDir); // verify that dump files exist if (!file_exists($dumpPath1) || !file_exists($dumpPath2)) { showError("DB Dump files cannot be found. Aborting..."); } /* showMessage3( "altering db with charset '$charset'" ); $command = $sqlplus . " @$commandPath"; file_put_contents( $commandPath, $alterdb ); eZExecuteShellCommand( $command, "failed to alter db. tried command '$command'"); */ showMessage3(''); showMessage3("Now you will have to alter the database character set."); showMessage3("The recommended way is to create a new database from scratch"); showMessage3("using AL32UTF8 as character set (THIS IS VERY IMPORTANT),"); showMessage3("and delete the existing one."); showMessage3("The new database should be empty (all schemas will be recreated by this script)"); showMessage3("and have the same DBA account as the old one."); showMessage3("It should also use the same connect identifier as the old one."); showMessage3(''); showMessage3("PLEASE do not terminate this php script while doing that,"); showMessage3("use a different command line shell."); showMessage3(''); $continue = eZGetUserInput("Press Y when you are ready to continue... "); if ($continue != 'y' && $continue != 'Y') { showError("Aborting"); } // connect to new db with dba account, check that charset is OK while (true) { $db = eZDB::instance(false, array('user' => $oracleDbaAccount['user'], 'password' => $oracleDbaAccount['password']), true); if (!$db->isConnected()) { showWarning("Cannot connect to the new database.\n" . "Please check that it is up and running before continuing"); } else { $oracleCharset = $db->arrayQuery("select value from nls_database_parameters where parameter = 'NLS_CHARACTERSET'"); $oracleCharset = $oracleCharset[0]['value']; $db->close(); if ($oracleCharset == 'AL32UTF8') { break; } else { showWarning("The new database uses the {$oracleCharset} character set instead of AL32UTF8.\n" . "Please recreate the database using AL32UTF8 before continuing"); } } $continue = eZGetUserInput("Press Y when you are ready to continue. Any other letter to abort "); if ($continue != 'y' && $continue != 'Y') { showError("Aborting"); } } // restore dump into newly created db showMessage3(" restoring db dump"); chdir($oracleHome . '/bin'); eZExecuteShellCommand($impdb1, "failed to restore db dump. tried command '{$impdb1}'"); eZExecuteShellCommand($impdb2, "failed to restore db dump. tried command '{$impdb2}'"); chdir($eZDir); showMessage3(" cleaning up"); // clean up eZDir::recursiveDelete($dumpPath1); eZDir::recursiveDelete($dumpPath2); } // re-initialize db interface, *** this time in UTF8 - with the standard user *** $db = eZDB::instance(false, array('charset' => 'utf8'), true); if (!$db->isConnected()) { showError("Cannot reconnect to DB. Aborting..."); } //$db->begin(); }
/** * Clear Template Compile cache */ static function clearTemplateCompileCache() { eZDir::recursiveDelete(eZTemplateCompiler::compilationDirectory()); }
function install( $package, $installType, $parameters, $name, $os, $filename, $subdirectory, $content, &$installParameters, &$installData ) { //$this->Package =& $package; $trans = eZCharTransform::instance(); $name = $content->getAttribute( 'name' ); $extensionName = $trans->transformByGroup( $name, 'urlalias' ); if ( strcmp( $name, $extensionName ) !== 0 ) { $description = ezpI18n::tr( 'kernel/package', 'Package contains an invalid extension name: %extensionname', false, array( '%extensionname' => $name ) ); $installParameters['error'] = array( 'error_code' => false, 'element_id' => $name, 'description' => $description ); return false; } $siteINI = eZINI::instance(); $extensionRootDir = $siteINI->variable( 'ExtensionSettings', 'ExtensionDirectory' ); $extensionDir = $extensionRootDir . '/' . $extensionName; $packageExtensionDir = $package->path() . '/' . $parameters['sub-directory'] . '/' . $extensionName; // Error: extension already exists. if ( file_exists( $extensionDir ) ) { $description = ezpI18n::tr( 'kernel/package', "Extension '%extensionname' already exists.", false, array( '%extensionname' => $extensionName ) ); $choosenAction = $this->errorChoosenAction( self::ERROR_EXISTS, $installParameters, $description, $this->HandlerType ); switch( $choosenAction ) { case self::ACTION_SKIP: return true; case eZPackage::NON_INTERACTIVE: case self::ACTION_REPLACE: eZDir::recursiveDelete( $extensionDir ); break; default: $installParameters['error'] = array( 'error_code' => self::ERROR_EXISTS, 'element_id' => $extensionName, 'description' => $description, 'actions' => array( self::ACTION_REPLACE => ezpI18n::tr( 'kernel/package', "Replace extension" ), self::ACTION_SKIP => ezpI18n::tr( 'kernel/package', 'Skip' ) ) ); return false; } } eZDir::mkdir( $extensionDir, false, true ); eZDir::copy( $packageExtensionDir, $extensionRootDir ); // Regenerate autoloads for extensions to pick up the newly created extension ezpAutoloader::updateExtensionAutoloadArray(); // Activate extension $siteINI = eZINI::instance( 'site.ini', 'settings/override', null, null, false, true ); if ( $siteINI->hasVariable( 'ExtensionSettings', "ActiveExtensions" ) ) { $selectedExtensions = $siteINI->variable( 'ExtensionSettings', "ActiveExtensions" ); } else { $selectedExtensions = array(); } if ( !in_array( $extensionName, $selectedExtensions ) ) { $selectedExtensions[] = $extensionName; $siteINI->setVariable( "ExtensionSettings", "ActiveExtensions", $selectedExtensions ); $siteINI->save( 'site.ini.append', '.php', false, false ); } return true; }
static function removeFiles($path) { if (file_exists($path)) { eZDir::recursiveDelete($path); } }
/** * Import object. * * @param Array getParameters. * @param Array getOptions. * @param Array postParameters. * @param Array postOptions. * @param string Import type. * * @return DOMElement DOMElement containing OO document. */ protected function importOODocument($getParams, $getOptions, $postParams, $postOptions, $importType = 'import') { $nodeID = $postParams['nodeID']; $data = $postParams['data']; // Alex 2008/04/22 - Added format argument: 'odt' (default), 'doc' $format = $postOptions['format']; $languageCode = $postOptions['languageCode']; $base64Encoded = $postOptions['base64Encoded']; $node = eZContentObjectTreeNode::fetch($nodeID, $languageCode); if (!$node) { throw new Exception('Could not fetch node: ' . $nodeID); } // Decode data. if ($base64Encoded) { // Alex 2008/04/16 - Added str_replace() $data = base64_decode(str_replace(' ', '+', $data)); } // Store data to temporary file. // Alex 2008/04/22 - Added format argument: 'odt' (default), 'doc' $filename = substr(md5(mt_rand()), 0, 8) . ".{$format}"; $tmpFilePath = eZSys::cacheDirectory() . '/ezodf/' . substr(md5(mt_rand()), 0, 8); $tmpFilename = $tmpFilePath . '/' . $filename; if (!eZFile::create($filename, $tmpFilePath, $data)) { throw new Exception('Could not create file: ' . $tmpFilename); } $import = new eZOOImport(); $result = $import->import($tmpFilename, $nodeID, $filename, $importType); eZDir::recursiveDelete($tmpFilePath); if (!$result) { throw new Exception('OO import failed: ' . $import->getErrorNumber() . ' - ' . $import->getErrorMessage()); } $domDocument = new DOMDocument('1.0', 'utf-8'); $importElement = $domDocument->createElement('OOImport'); // Add node info about imported document. $importElement->appendChild($this->createTreeNodeDOMElement($domDocument, $result['MainNode'])); return $importElement; }
function writeDocument() { $ooINI = eZINI::instance('odf.ini'); // Initalize directories eZDir::mkdir($this->OORootDir); eZDir::mkdir($this->OOExportDir . "META-INF", false, true); eZDir::mkdir($this->OOTemplateDir); $metaXML = "<?xml version='1.0' encoding='UTF-8'?>" . "<office:document-meta xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:meta='urn:oasis:names:tc:opendocument:xmlns:meta:1.0' xmlns:ooo='http://openoffice.org/2004/office' office:version='1.0' xmlns:ezpublish='http://www.ez.no/ezpublish/oasis'>" . "<office:meta>" . "<meta:generator>eZ Publish</meta:generator>" . " <meta:creation-date>2004-11-10T11:39:50</meta:creation-date>" . " <dc:date>2004-11-10T11:40:15</dc:date>" . " <dc:language>en-US</dc:language>" . " <meta:editing-cycles>3</meta:editing-cycles>" . " <meta:editing-duration>PT26S</meta:editing-duration>" . " <meta:user-defined meta:name='Info 1'/>" . " <meta:user-defined meta:name='Info 2'/>" . " <meta:user-defined meta:name='Info 3'/>" . " <meta:user-defined meta:name='Info 4'/>" . " <meta:document-statistic meta:table-count='0' meta:image-count='0' meta:object-count='0' meta:page-count='1' meta:paragraph-count='1' meta:word-count='2' meta:character-count='10'/>" . " </office:meta>" . "</office:document-meta>"; file_put_contents($this->OOExportDir . "meta.xml", $metaXML); $settingsXML = "<?xml version='1.0' encoding='UTF-8'?>" . "<office:document-settings xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:config='urn:oasis:names:tc:opendocument:xmlns:config:1.0' xmlns:ooo='http://openoffice.org/2004/office' office:version='1.0'>" . " <office:settings>" . " </office:settings>" . "</office:document-settings>"; file_put_contents($this->OOExportDir . "settings.xml", $settingsXML); $useTemplate = $ooINI->variable('ODFExport', 'UseTemplate') == "true"; $templateName = $ooINI->variable('ODFExport', 'TemplateName'); if ($useTemplate) { $templateFile = "extension/ezodf/templates/" . $templateName; $archiveOptions = new ezcArchiveOptions(array('readOnly' => true)); $archive = ezcArchive::open($templateFile, null, $archiveOptions); $archive->extract($this->OOTemplateDir); // Copy styles.xml and images, if any to the document being generated if (!copy($this->OOTemplateDir . "styles.xml", $this->OOExportDir . "styles.xml")) { return array(self::ERROR_COULD_NOT_COPY, "Could not copy the styles.xml file."); } $sourceDir = $this->OOTemplateDir . "Pictures"; $destDir = $this->OOExportDir . "Pictures"; eZDir::mkdir($destDir, false, true); eZDir::copy($sourceDir, $destDir, false, true); } else { // Generate a default empty styles.xml file $stylesXML = "<?xml version='1.0' encoding='UTF-8'?>" . "<office:document-styles xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0' xmlns:style='urn:oasis:names:tc:opendocument:xmlns:style:1.0' xmlns:text='urn:oasis:names:tc:opendocument:xmlns:text:1.0' xmlns:table='urn:oasis:names:tc:opendocument:xmlns:table:1.0' xmlns:draw='urn:oasis:names:tc:opendocument:xmlns:drawing:1.0' xmlns:fo='urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:meta='urn:oasis:names:tc:opendocument:xmlns:meta:1.0' xmlns:number='urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0' xmlns:svg='urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0' xmlns:chart='urn:oasis:names:tc:opendocument:xmlns:chart:1.0' xmlns:dr3d='urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0' xmlns:math='http://www.w3.org/1998/Math/MathML' xmlns:form='urn:oasis:names:tc:opendocument:xmlns:form:1.0' xmlns:script='urn:oasis:names:tc:opendocument:xmlns:script:1.0' xmlns:ooo='http://openoffice.org/2004/office' xmlns:ooow='http://openoffice.org/2004/writer' xmlns:oooc='http://openoffice.org/2004/calc' xmlns:dom='http://www.w3.org/2001/xml-events' office:version='1.0'>" . " <office:font-face-decls>" . " </office:font-face-decls>" . " <office:styles>" . " <style:style style:name='Table_20_Heading' style:display-name='Table Heading' style:family='paragraph' style:parent-style-name='Table_20_Contents' style:class='extra'>" . " <style:paragraph-properties fo:text-align='center' style:justify-single-word='false' text:number-lines='false' text:line-number='0'/>" . " <style:text-properties fo:font-style='italic' fo:font-weight='bold' style:font-style-asian='italic' style:font-weight-asian='bold' style:font-style-complex='italic' style:font-weight-complex='bold'/>" . " </style:style>" . " <style:style style:name='Preformatted_20_Text' style:display-name='Preformatted Text' style:family='paragraph' style:parent-style-name='Standard' style:class='html'>" . " <style:paragraph-properties fo:margin-top='0in' fo:margin-bottom='0in'/>" . " <style:text-properties style:font-name='Courier New' fo:font-size='10pt' style:font-name-asian='Courier New' style:font-size-asian='10pt' style:font-name-complex='Courier New' style:font-size-complex='10pt'/>" . " </style:style>" . " <style:style style:name='eZCustom_20_factbox' style:display-name='eZCustom_20_factbox' style:family='paragraph' style:parent-style-name='Standard' style:class='text'>" . " <style:paragraph-properties fo:margin-top='0in' fo:margin-bottom='0in'/>" . " <style:text-properties style:font-name='Helvetica' fo:font-size='10pt' style:font-name-asian='Helvetica' style:font-size-asian='10pt' style:font-name-complex='Helvetica' style:font-size-complex='10pt'/>" . " </style:style>" . " <style:style style:name='eZCustom_20_quote' style:display-name='eZCustom_20_quote' style:family='paragraph' style:parent-style-name='Standard' style:class='text'>" . " <style:paragraph-properties fo:margin-top='0in' fo:margin-bottom='0in'/>" . " <style:text-properties style:font-name='Helvetica' fo:font-size='10pt' style:font-name-asian='Helvetica' style:font-size-asian='10pt' style:font-name-complex='Helvetica' style:font-size-complex='10pt'/>" . " </style:style>" . " </office:styles>" . "</office:document-styles>"; file_put_contents($this->OOExportDir . "styles.xml", $stylesXML); } $mimeType = "application/vnd.oasis.opendocument.text"; file_put_contents($this->OOExportDir . "mimetype", $mimeType); // Write content XML file $contentXML = "<?xml version='1.0' encoding='UTF-8'?>" . "<!DOCTYPE office:document-content PUBLIC '-//OpenOffice.org//DTD OfficeDocument1.0//EN' 'office.dtd'>" . "<office:document-content xmlns:office='urn:oasis:names:tc:opendocument:xmlns:office:1.0'" . " xmlns:meta='urn:oasis:names:tc:opendocument:xmlns:meta:1.0'" . " xmlns:config='urn:oasis:names:tc:opendocument:xmlns:config:1.0'" . " xmlns:text='urn:oasis:names:tc:opendocument:xmlns:text:1.0'" . " xmlns:table='urn:oasis:names:tc:opendocument:xmlns:table:1.0'" . " xmlns:draw='urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'" . " xmlns:presentation='urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'" . " xmlns:dr3d='urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'" . " xmlns:chart='urn:oasis:names:tc:opendocument:xmlns:chart:1.0'" . " xmlns:form='urn:oasis:names:tc:opendocument:xmlns:form:1.0'" . " xmlns:script='urn:oasis:names:tc:opendocument:xmlns:script:1.0'" . " xmlns:style='urn:oasis:names:tc:opendocument:xmlns:style:1.0'" . " xmlns:number='urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'" . " xmlns:math='http://www.w3.org/1998/Math/MathML'" . " xmlns:svg='urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'" . " xmlns:fo='urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'" . " xmlns:koffice='http://www.koffice.org/2005/'" . " xmlns:dc='http://purl.org/dc/elements/1.1/'" . " xmlns:xlink='http://www.w3.org/1999/xlink'>" . " <office:script/>" . " <office:font-face-decls/>" . " <office:automatic-styles>" . " <text:list-style style:name='bulletlist'>" . " <text:list-level-style-bullet text:level='1' text:style-name='Bullet_20_Symbols' style:num-suffix='.' text:bullet-char='●'>" . " <style:list-level-properties text:space-before='0.25in' text:min-label-width='0.25in'/>" . " <style:text-properties style:font-name='StarSymbol'/>" . " </text:list-level-style-bullet>" . " <text:list-level-style-bullet text:level='2' text:style-name='Bullet_20_Symbols' style:num-suffix='.' text:bullet-char='○'>" . " <style:list-level-properties text:space-before='0.5in' text:min-label-width='0.25in'/>" . " <style:text-properties style:font-name='StarSymbol'/>" . " </text:list-level-style-bullet>" . " <text:list-level-style-bullet text:level='3' text:style-name='Bullet_20_Symbols' style:num-suffix='.' text:bullet-char='■'>" . " <style:list-level-properties text:space-before='0.75in' text:min-label-width='0.25in'/>" . " <style:text-properties style:font-name='StarSymbol'/>" . " </text:list-level-style-bullet>" . " </text:list-style>" . " <text:list-style style:name='numberedlist'>" . " <text:list-level-style-number text:level='1' text:style-name='Numbering_20_Symbols' style:num-suffix='.' style:num-format='1'>" . " <style:list-level-properties text:space-before='0.25in' text:min-label-width='0.25in'/>" . " </text:list-level-style-number>" . " </text:list-style>" . " <style:style style:name='imagecentered' style:family='graphic' style:parent-style-name='Graphics'>" . " <style:graphic-properties style:horizontal-pos='center' style:horizontal-rel='paragraph' style:mirror='none' fo:clip='rect(0in 0in 0in 0in)' draw:luminance='0%' draw:contrast='0%' draw:red='0%' draw:green='0%' draw:blue='0%' draw:gamma='100%' draw:color-inversion='false' draw:image-opacity='100%' draw:color-mode='standard'/>" . " </style:style>" . " <style:style style:name='imageleft' style:family='graphic' style:parent-style-name='Graphics'>" . " <style:graphic-properties style:wrap='right' style:horizontal-pos='left' style:horizontal-rel='paragraph' style:mirror='none' fo:clip='rect(0in 0in 0in 0in)' draw:luminance='0%' draw:contrast='0%' draw:red='0%' draw:green='0%' draw:blue='0%' draw:gamma='100%' draw:color-inversion='false' draw:image-opacity='100%' draw:color-mode='standard'/>" . " </style:style>" . " <style:style style:name='imageright' style:family='graphic' style:parent-style-name='Graphics'>" . " <style:graphic-properties style:wrap='left' style:horizontal-pos='right' style:horizontal-rel='paragraph' style:mirror='none' fo:clip='rect(0in 0in 0in 0in)' draw:luminance='0%' draw:contrast='0%' draw:red='0%' draw:green='0%' draw:blue='0%' draw:gamma='100%' draw:color-inversion='false' draw:image-opacity='100%' draw:color-mode='standard'/>" . " </style:style>" . " <style:style style:name='T1' style:family='text'>" . " <style:text-properties fo:font-weight='bold' style:font-weight-asian='bold' style:font-weight-complex='bold'/>" . " </style:style>" . " <style:style style:name='T2' style:family='text'>" . " <style:text-properties fo:font-style='italic' style:font-style-asian='italic' style:font-style-complex='italic'/>" . " </style:style>" . " </office:automatic-styles>" . " <office:body>" . " <office:text>"; $bodyXML = ""; // Add body contents foreach ($this->DocumentArray as $element) { $bodyXML .= $this->handleElement($element); } // Handle charset conversion if needed $charset = 'UTF-8'; $codec = eZTextCodec::instance(false, $charset); $bodyXML = $codec->convertString($bodyXML); $contentXML .= $bodyXML; // Add the content end $contentXML .= "</office:text></office:body></office:document-content>"; file_put_contents($this->OOExportDir . "content.xml", $contentXML); // Write the manifest file $manifestXML = "<?xml version='1.0' encoding='UTF-8'?>" . "<!DOCTYPE manifest:manifest PUBLIC '-//OpenOffice.org//DTD Manifest 1.0//EN' 'Manifest.dtd'>" . "<manifest:manifest xmlns:manifest='urn:oasis:names:tc:opendocument:xmlns:manifest:1.0'>" . "<manifest:file-entry manifest:media-type='application/vnd.oasis.opendocument.text' manifest:full-path='/'/>" . "<manifest:file-entry manifest:media-type='application/vnd.sun.xml.ui.configuration' manifest:full-path='Configurations2/'/>" . "<manifest:file-entry manifest:media-type='' manifest:full-path='Pictures/'/>" . "<manifest:file-entry manifest:media-type='text/xml' manifest:full-path='content.xml'/>" . "<manifest:file-entry manifest:media-type='text/xml' manifest:full-path='styles.xml'/>" . "<manifest:file-entry manifest:media-type='text/xml' manifest:full-path='meta.xml'/>" . "<manifest:file-entry manifest:media-type='' manifest:full-path='Thumbnails/'/>" . "<manifest:file-entry manifest:media-type='text/xml' manifest:full-path='settings.xml'/>"; // Do not include the thumnail file. // "<manifest:file-entry manifest:media-type='' manifest:full-path='Thumbnails/thumbnail.png'/>" . foreach ($this->ImageFileArray as $imageFile) { $manifestXML .= "<manifest:file-entry manifest:media-type='' manifest:full-path='{$imageFile}'/>\n"; } $manifestXML .= "</manifest:manifest>"; file_put_contents($this->OOExportDir . "META-INF/manifest.xml", $manifestXML); $fileName = $this->OORootDir . "ootest.odt"; $zipArchive = ezcArchive::open($fileName, ezcArchive::ZIP); $zipArchive->truncate(); $prefix = $this->OOExportDir; $fileList = array(); eZDir::recursiveList($this->OOExportDir, $this->OOExportDir, $fileList); foreach ($fileList as $fileInfo) { $path = $fileInfo['type'] === 'dir' ? $fileInfo['path'] . '/' . $fileInfo['name'] . '/' : $fileInfo['path'] . '/' . $fileInfo['name']; $zipArchive->append(array($path), $prefix); } $zipArchive->close(); // Clean up eZDir::recursiveDelete($this->OOExportDir); eZDir::recursiveDelete($this->OOTemplateDir); // Clean up temporary image files if any $fileHandler = eZClusterFileHandler::instance(); foreach ($this->SourceImageArray as $sourceImageFile) { $fileHandler->fileDeleteLocal($sourceImageFile); } return $fileName; }
/** * Creates a new content or updates an existing one based on $file * * @param string $file the file to import * @param int $placeNodeID the node id where to place the new document or * the node of the document to update * @param string $originalFileName * @param string $importType "import" or "replace" * @param eZContentUpload|null $upload (not used in this method) * @param string|false $locale the locale to use while creating/updating * the content * @return array|false false if something went wrong */ function import($file, $placeNodeID, $originalFileName, $importType = "import", $upload = null, $locale = false) { $ooINI = eZINI::instance('odf.ini'); //$tmpDir = $ooINI->variable( 'ODFSettings', 'TmpDir' ); // Use var-directory as temporary directory $tmpDir = getcwd() . "/" . eZSys::cacheDirectory(); $allowedTypes = $ooINI->variable('DocumentType', 'AllowedTypes'); $convertTypes = $ooINI->variable('DocumentType', 'ConvertTypes'); $originalFileType = array_slice(explode('.', $originalFileName), -1, 1); $originalFileType = strtolower($originalFileType[0]); if (!in_array($originalFileType, $allowedTypes, false) and !in_array($originalFileType, $convertTypes, false)) { $this->setError(self::ERROR_UNSUPPORTEDTYPE, ezpI18n::tr('extension/ezodf/import/error', "Filetype: ") . $originalFileType); return false; } // If replacing/updating the document we need the ID. if ($importType == "replace") { $GLOBALS["OOImportObjectID"] = $placeNodeID; } // Check if we have access to node $place_node = eZContentObjectTreeNode::fetch($placeNodeID); $importClassIdentifier = $ooINI->variable('ODFImport', 'DefaultImportClass'); // Check if class exist $class = eZContentClass::fetchByIdentifier($importClassIdentifier); if (!is_object($class)) { eZDebug::writeError("Content class <strong>{$importClassIdentifier}</strong> specified in odf.ini does not exist."); $this->setError(self::ERROR_UNKNOWNCLASS, $importClassIdentifier); return false; } if (!is_object($place_node)) { $locationOK = false; if ($upload !== null) { $parentNodes = false; $parentMainNode = false; $locationOK = $upload->detectLocations($importClassIdentifier, $class, $placeNodeID, $parentNodes, $parentMainNode); } if ($locationOK === false || $locationOK === null) { $this->setError(self::ERROR_UNKNOWNNODE, ezpI18n::tr('extension/ezodf/import/error', "Unable to fetch node with id ") . $placeNodeID); return false; } $placeNodeID = $parentMainNode; $place_node = eZContentObjectTreeNode::fetch($placeNodeID); } // Check if document conversion is needed // // Alex 2008/04/21 - added !== false if (in_array($originalFileType, $convertTypes, false) !== false) { $uniqueStamp = md5(time()); $tmpFromFile = $tmpDir . "/convert_from_{$uniqueStamp}.doc"; $tmpToFile = $tmpDir . "/ooo_converted_{$uniqueStamp}.odt"; copy(realpath($file), $tmpFromFile); /// Convert document using the eZ Publish document conversion daemon if (!$this->daemonConvert($tmpFromFile, $tmpToFile)) { if ($this->getErrorNumber() == 0) { $this->setError(self::ERROR_CONVERT); } return false; } // At this point we can unlink the sourcefile for conversion unlink($tmpFromFile); // Overwrite the file location $file = $tmpToFile; } $importResult = array(); $unzipResult = ""; $uniqueImportDir = $this->ImportDir; eZDir::mkdir($uniqueImportDir, false, true); $http = eZHTTPTool::instance(); $archiveOptions = new ezcArchiveOptions(array('readOnly' => true)); $archive = ezcArchive::open($file, null, $archiveOptions); $archive->extract($uniqueImportDir); $fileName = $uniqueImportDir . "content.xml"; $dom = new DOMDocument('1.0', 'UTF-8'); $success = $dom->load($fileName); $sectionNodeHash = array(); // At this point we could unlink the destination file from the conversion, if conversion was used if (isset($tmpToFile)) { unlink($tmpToFile); } if (!$success) { $this->setError(self::ERROR_PARSEXML); return false; } // Fetch the automatic document styles $automaticStyleArray = $dom->getElementsByTagNameNS(self::NAMESPACE_OFFICE, 'automatic-styles'); if ($automaticStyleArray->length == 1) { $this->AutomaticStyles = $automaticStyleArray->item(0)->childNodes; } // Fetch the body section content $sectionNodeArray = $dom->getElementsByTagNameNS(self::NAMESPACE_TEXT, 'section'); $customClassFound = false; if ($sectionNodeArray->length > 0) { $registeredClassArray = $ooINI->variable('ODFImport', 'RegisteredClassArray'); // Check the defined sections in OO document $sectionNameArray = array(); foreach ($sectionNodeArray as $sectionNode) { $sectionNameArray[] = strtolower($sectionNode->getAttributeNS(self::NAMESPACE_TEXT, "name")); } // Check if there is a coresponding eZ Publish class for this document foreach ($registeredClassArray as $className) { $attributeArray = $ooINI->variable($className, 'Attribute'); if (!empty($attributeArray)) { // Convert space to _ in section names foreach ($sectionNameArray as $key => $value) { $sectionNameArray[$key] = str_replace(" ", "_", $value); } sort($attributeArray); sort($sectionNameArray); $diff = array_diff($attributeArray, $sectionNameArray); if (empty($diff)) { $importClassIdentifier = $className; $customClassFound = true; break; } } } if ($customClassFound == true) { foreach ($sectionNodeArray as $sectionNode) { $sectionName = str_replace(" ", "_", strtolower($sectionNode->getAttributeNS(self::NAMESPACE_TEXT, 'name'))); $xmlText = ""; $level = 1; $childArray = $sectionNode->childNodes; $nodeCount = 1; foreach ($childArray as $childNode) { if ($childNode->nodeType === XML_ELEMENT_NODE) { $isLastTag = $nodeCount == $childArray->length; $xmlText .= self::handleNode($childNode, $level, $isLastTag); } $nodeCount++; } $endSectionPart = ""; $levelDiff = 1 - $level; if ($levelDiff < 0) { $endSectionPart = str_repeat("</section>", abs($levelDiff)); } $charset = eZTextCodec::internalCharset(); // Store the original XML for each section, since some datatypes needs to handle the XML specially $sectionNodeHash[$sectionName] = $sectionNode; $xmlTextArray[$sectionName] = "<?xml version='1.0' encoding='{$charset}' ?>" . "<section xmlns:image='http://ez.no/namespaces/ezpublish3/image/' " . " xmlns:xhtml='http://ez.no/namespaces/ezpublish3/xhtml/'><section>" . $xmlText . $endSectionPart . "</section></section>"; } } } if ($customClassFound == false) { // No defined sections. Do default import. $bodyNodeArray = $dom->getElementsByTagNameNS(self::NAMESPACE_OFFICE, 'text'); // Added by Soushi // check the parent-style-name [ eZSectionDefinition ] $eZSectionDefinitionStyleName = array(); foreach ($automaticStyleArray->item(0)->childNodes as $child) { if ($child->nodeType === XML_ELEMENT_NODE && $child->getAttributeNS(self::NAMESPACE_STYLE, 'parent-style-name') === 'eZSectionDefinition') { $eZSectionDefinitionStyleName[] = $child->getAttributeNS(self::NAMESPACE_STYLE, 'name'); } } $sectionNameArray = array(); $sectionNodeArray = array(); $paragraphSectionName = NULL; $firstChildFlag = false; $paragraphSectionNodeArray = array(); foreach ($bodyNodeArray->item(0)->childNodes as $childNode) { $firstChildFlag = true; if ($childNode->nodeType === XML_ELEMENT_NODE && (in_array($childNode->getAttributeNS(self::NAMESPACE_TEXT, 'style-name'), $eZSectionDefinitionStyleName) || $childNode->getAttributeNS(self::NAMESPACE_TEXT, 'style-name') === 'eZSectionDefinition')) { $firstChildFlag = false; $childNodeChildren = $childNode->childNodes; $paragraphSectionName = trim($childNodeChildren->item(0)->textContent); $sectionNameArray[] = $paragraphSectionName; } if ($paragraphSectionName && $firstChildFlag) { $paragraphSectionNodeArray[$paragraphSectionName][] = $childNode; } } $sectionNodeArray = array(); foreach ($paragraphSectionNodeArray as $key => $childNodes) { $sectionNode = $dom->createElement('section'); foreach ($childNodes as $childNode) { $sectionNode->appendChild($childNode); } $sectionNodeArray[$key] = $sectionNode; } $customClassFound = false; if ($sectionNameArray) { $registeredClassArray = $ooINI->variable('ODFImport', 'RegisteredClassArray'); // Check if there is a coresponding eZ Publish class for this document foreach ($registeredClassArray as $className) { $attributeArray = $ooINI->variable($className, 'Attribute'); if (!empty($attributeArray)) { // Convert space to _ in section names foreach ($sectionNameArray as $key => $value) { $sectionNameArray[$key] = str_replace(" ", "_", $value); } sort($attributeArray); sort($sectionNameArray); $diff = array_diff($attributeArray, $sectionNameArray); if (empty($diff)) { $importClassIdentifier = $className; $customClassFound = true; break; } } } } if ($sectionNameArray && $customClassFound == true) { foreach ($sectionNodeArray as $key => $sectionNode) { $sectionName = str_replace(" ", "_", $key); $xmlText = ""; $level = 1; foreach ($sectionNode->childNodes as $childNode) { $isLastTag = !isset($childNode->nextSibling); $xmlText .= self::handleNode($childNode, $level, $isLastTag); } $endSectionPart = ""; $levelDiff = 1 - $level; if ($levelDiff < 0) { $endSectionPart = str_repeat("</section>", abs($levelDiff)); } $charset = eZTextCodec::internalCharset(); // Store the original XML for each section, since some datatypes needs to handle the XML specially $sectionNodeHash[$sectionName] = $sectionNode; $xmlTextArray[$sectionName] = "<?xml version='1.0' encoding='{$charset}' ?>" . "<section xmlns:image='http://ez.no/namespaces/ezpublish3/image/' " . " xmlns:xhtml='http://ez.no/namespaces/ezpublish3/xhtml/'><section>" . $xmlText . $endSectionPart . "</section></section>"; } } else { if ($bodyNodeArray->length === 1) { $xmlText = ""; $level = 1; foreach ($bodyNodeArray->item(0)->childNodes as $childNode) { $xmlText .= self::handleNode($childNode, $level); } $endSectionPart = ""; $levelDiff = 1 - $level; if ($levelDiff < 0) { $endSectionPart = str_repeat("</section>", abs($levelDiff)); } $charset = eZTextCodec::internalCharset(); $xmlTextBody = "<?xml version='1.0' encoding='{$charset}' ?>" . "<section xmlns:image='http://ez.no/namespaces/ezpublish3/image/' " . " xmlns:xhtml='http://ez.no/namespaces/ezpublish3/xhtml/'><section>" . $xmlText . $endSectionPart . "</section></section>"; } } } if ($importType == "replace") { // Check if we are allowed to edit the node $functionCollection = new eZContentFunctionCollection(); $access = $functionCollection->checkAccess('edit', $place_node, false, false, $locale); } else { // Check if we are allowed to create a node under the node $functionCollection = new eZContentFunctionCollection(); $access = $functionCollection->checkAccess('create', $place_node, $importClassIdentifier, $place_node->attribute('class_identifier'), $locale); } if ($access['result']) { // Check if we should replace the current object or import a new if ($importType !== "replace") { $class = eZContentClass::fetchByIdentifier($importClassIdentifier); $place_object = $place_node->attribute('object'); $sectionID = $place_object->attribute('section_id'); $creatorID = $this->currentUserID; $parentNodeID = $placeNodeID; if (!is_object($class)) { eZDebug::writeError("Content class <strong>{$importClassIdentifier}</strong> specified in odf.ini does not exist."); $this->setError(self::ERROR_UNKNOWNCLASS, $importClassIdentifier); return false; } $object = $class->instantiate($creatorID, $sectionID, false, $locale); $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version'), 'parent_node' => $parentNodeID, 'is_main' => 1)); $nodeAssignment->store(); $version = $object->version(1); $version->setAttribute('modified', eZDateTime::currentTimeStamp()); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $version->store(); $dataMap = $object->dataMap(); } else { // Check if class is supported before we start changing anything $placeClassIdentifier = $place_node->attribute('class_identifier'); if ($ooINI->hasVariable($placeClassIdentifier, 'DefaultImportTitleAttribute') && $ooINI->hasVariable($placeClassIdentifier, 'DefaultImportBodyAttribute')) { $titleAttribute = $ooINI->variable($placeClassIdentifier, 'DefaultImportTitleAttribute'); $bodyAttribute = $ooINI->variable($placeClassIdentifier, 'DefaultImportBodyAttribute'); // Extra check to see if attributes exist in dataMap (config is not wrong) $dataMap = $place_node->attribute('data_map'); if (!isset($dataMap[$titleAttribute]) || !isset($dataMap[$bodyAttribute])) { $this->setError(self::ERROR_IMPORTING, "Error in configuration for {$placeClassIdentifier}, please check configuration file."); return false; } unset($dataMap); } else { $this->setError(self::ERROR_IMPORTING, "No settings for replacing node of type {$placeClassIdentifier}. Stopping."); return false; } // Change class for importing $importClassIdentifier = $placeClassIdentifier; // already fetched: $node = eZContentObjectTreeNode::fetch( $placeNodeID ); $object = $place_node->attribute('object'); $version = $object->createNewVersionIn($locale); $dataMap = $version->dataMap(); } $contentObjectID = $object->attribute('id'); if ($customClassFound == true) { // Initialize the actual object attributes $attributeArray = $ooINI->variable($importClassIdentifier, 'Attribute'); foreach ($attributeArray as $attributeIdentifier => $sectionName) { switch ($dataMap[$attributeIdentifier]->DataTypeString) { case "ezstring": case "eztext": if (!isset($xmlTextArray[$sectionName])) { continue; } $eztextDom = new DOMDOcument('1.0', 'UTF-8'); $eztextDom->loadXML($xmlTextArray[$sectionName]); $text = $eztextDom->documentElement->textContent; $dataMap[$attributeIdentifier]->setAttribute('data_text', trim($text)); $dataMap[$attributeIdentifier]->store(); break; case "ezxmltext": if (!isset($xmlTextArray[$sectionName])) { continue; } $dataMap[$attributeIdentifier]->setAttribute('data_text', $xmlTextArray[$sectionName]); $dataMap[$attributeIdentifier]->store(); break; case "ezdate": // Only support date formats as a single paragraph in a section with the format: // day/month/year if (!isset($xmlTextArray[$sectionName])) { continue; } $dateString = strip_tags($xmlTextArray[$sectionName]); $dateArray = explode("/", $dateString); if (count($dateArray) == 3) { $year = $dateArray[2]; $month = $dateArray[1]; $day = $dateArray[0]; $date = new eZDate(); $contentClassAttribute = $dataMap[$attributeIdentifier]; $date->setMDY($month, $day, $year); $dataMap[$attributeIdentifier]->setAttribute('data_int', $date->timeStamp()); $dataMap[$attributeIdentifier]->store(); } break; case "ezdatetime": // Only support date formats as a single paragraph in a section with the format: // day/month/year 14:00 if (!isset($xmlTextArray[$sectionName])) { continue; } $dateString = trim(strip_tags($xmlTextArray[$sectionName])); $dateTimeArray = explode(" ", $dateString); $dateArray = explode("/", $dateTimeArray[0]); $timeArray = explode(":", $dateTimeArray[1]); if (count($dateArray) == 3 and count($timeArray) == 2) { $year = $dateArray[2]; $month = $dateArray[1]; $day = $dateArray[0]; $hour = $timeArray[0]; $minute = $timeArray[1]; $dateTime = new eZDateTime(); $contentClassAttribute = $dataMap[$attributeIdentifier]; $dateTime->setMDYHMS($month, $day, $year, $hour, $minute, 0); $dataMap[$attributeIdentifier]->setAttribute('data_int', $dateTime->timeStamp()); $dataMap[$attributeIdentifier]->store(); } break; case "ezimage": $hasImage = false; // Images are treated as an image object inside a paragrah. // We fetch the first image object if there are multiple and ignore the rest if (is_object($sectionNodeHash[$sectionName])) { // Look for paragraphs in the section foreach ($sectionNodeHash[$sectionName]->childNodes as $paragraph) { if (!$paragraph->hasChildNodes()) { continue; } // Look for frame node foreach ($paragraph->childNodes as $frame) { // finally look for the image node $children = $frame->childNodes; $imageNode = $children->item(0); if ($imageNode && $imageNode->localName == "image") { $fileName = ltrim($imageNode->getAttributeNS(self::NAMESPACE_XLINK, 'href'), '#'); $filePath = $this->ImportDir . $fileName; if (file_exists($filePath)) { $imageContent = $dataMap[$attributeIdentifier]->attribute('content'); $imageContent->initializeFromFile($filePath, false, basename($filePath)); $imageContent->store($dataMap[$attributeIdentifier]); $dataMap[$attributeIdentifier]->store(); } $hasImage = true; } } } } if (!$hasImage) { $imageHandler = $dataMap[$attributeIdentifier]->attribute('content'); if ($imageHandler) { $imageHandler->removeAliases($dataMap[$attributeIdentifier]); } } break; case "ezmatrix": $matrixHeaderArray = array(); // Fetch the current defined columns in the matrix $matrix = $dataMap[$attributeIdentifier]->content(); $columns = $matrix->attribute("columns"); foreach ($columns['sequential'] as $column) { $matrixHeaderArray[] = $column['name']; } $headersValid = true; $originalHeaderCount = count($matrixHeaderArray); $headerCount = 0; $rowCount = 0; $cellArray = array(); // A matrix is supported as a table inside sections. If multiple tables are present we take the first. if (is_object($sectionNodeHash[$sectionName])) { // Look for paragraphs in the section foreach ($sectionNodeHash[$sectionName]->childNodes as $table) { if ($table->localName == "table") { // Loop the rows in the table foreach ($table->childNodes as $row) { // Check the headers and compare with the defined matrix if ($row->localName == "table-header-rows") { $rowArray = $row->childNodes; if ($rowArray->length == 1) { foreach ($rowArray->item(0)->childNodes as $headerCell) { if ($headerCell->localName == "table-cell") { $paragraphArray = $headerCell->childNodes; if ($paragraphArray->length == 1) { $headerName = $paragraphArray->item(0)->textContent; if ($matrixHeaderArray[$headerCount] != $headerName) { $headersValid = false; } $headerCount++; } } } } } // Check the rows if ($row->localName == "table-row") { foreach ($row->childNodes as $cell) { if ($cell->childNodes->length >= 1) { $firstParagraph = $cell->childNodes->item(0); $cellArray[] = $firstParagraph->textContent; } } $rowCount++; } } } } } if ($headerCount == $originalHeaderCount and $headersValid == true) { // Remove all existing rows for ($i = 0; $i < $matrix->attribute("rowCount"); $i++) { $matrix->removeRow($i); } // Insert new rows $matrix->addRow(false, $rowCount); $matrix->Cells = $cellArray; $dataMap[$attributeIdentifier]->setAttribute('data_text', $matrix->xmlString()); $matrix->decodeXML($dataMap[$attributeIdentifier]->attribute('data_text')); $dataMap[$attributeIdentifier]->setContent($matrix); $dataMap[$attributeIdentifier]->store(); } break; default: eZDebug::writeError("Unsupported datatype for OpenOffice.org import: " . $dataMap[$attributeIdentifier]->DataTypeString); break; } } } else { // Check if attributes are already fetched if (!isset($titleAttribute) || !isset($bodyAttribute)) { // Set attributes accorring to import class $titleAttribute = $ooINI->variable($importClassIdentifier, 'DefaultImportTitleAttribute'); $bodyAttribute = $ooINI->variable($importClassIdentifier, 'DefaultImportBodyAttribute'); } $objectName = basename($originalFileName); // Remove extension from name $objectName = preg_replace("/(\\....)\$/", "", $objectName); // Convert _ to spaces and upcase the first character $objectName = ucfirst(str_replace("_", " ", $objectName)); $dataMap[$titleAttribute]->setAttribute('data_text', $objectName); $dataMap[$titleAttribute]->store(); $dataMap[$bodyAttribute]->setAttribute('data_text', $xmlTextBody); $dataMap[$bodyAttribute]->store(); } $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => $version->attribute('version'))); $storeImagesInMedia = $ooINI->variable("ODFImport", "PlaceImagesInMedia") == "true"; if ($storeImagesInMedia == true) { // Fetch object to get correct name $object = eZContentObject::fetch($contentObjectID); $contentINI = eZINI::instance('content.ini'); $mediaRootNodeID = $contentINI->variable("NodeSettings", "MediaRootNode"); $node = eZContentObjectTreeNode::fetch($mediaRootNodeID); $articleFolderName = $object->attribute('name'); $importFolderName = $ooINI->variable('ODFImport', 'ImportedImagesMediaNodeName'); $importNode = self::createSubNode($node, $importFolderName); $articleNode = self::createSubNode($importNode, $articleFolderName); $imageRootNode = $articleNode->attribute("node_id"); } else { $imageRootNode = $object->attribute("main_node_id"); } // Publish all embedded images as related objects foreach ($this->RelatedImageArray as $image) { // Publish related images $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $image['ID'], 'contentobject_version' => 1, 'parent_node' => $imageRootNode, 'is_main' => 1)); $nodeAssignment->store(); eZOperationHandler::execute('content', 'publish', array('object_id' => $image['ID'], 'version' => 1)); $object->addContentObjectRelation($image['ID'], 1); } $mainNode = $object->attribute('main_node'); // Create object stop. $importResult['Object'] = $object; $importResult['Published'] = $operationResult['status'] == eZModuleOperationInfo::STATUS_CONTINUE; if ($mainNode instanceof eZContentObjectTreeNode) { $importResult['MainNode'] = $mainNode; $importResult['URLAlias'] = $mainNode->attribute('url_alias'); $importResult['NodeName'] = $mainNode->attribute('name'); } else { $importResult['MainNode'] = false; $importResult['URLAlias'] = false; $importResult['NodeName'] = false; } $importResult['ClassIdentifier'] = $importClassIdentifier; } else { $this->setError(self::ERROR_ACCESSDENIED); return false; } // Clean up eZDir::recursiveDelete($uniqueImportDir); return $importResult; }
<?php /** * File containing the ezie no save & quit menu item handler * * @copyright Copyright (C) eZ Systems AS. * @license For full copyright and license information view LICENSE file distributed with this source code. * @version //autogentag// * @package ezie */ $prepare_action = new eZIEImagePreAction(); // @todo Use the cluster handler code // delete all the images in working directory // delete working directory $working_folder = eZDir::dirpath($prepare_action->getImagePath()); // deletes the working folder recursively eZDir::recursiveDelete($working_folder); // @todo delete the user directory if empty echo json_encode(new StdClass()); eZExecution::cleanExit();
/** * Removes a directory and all it's contents, recursively. * * @param string $dir Directory to remove * @param bool $rootCheck Check whether $dir is supposed to be contained in * eZ Publish root directory * @return bool True if the operation succeeded, false otherwise */ static function recursiveDelete( $dir, $rootCheck = true ) { // RecursiveDelete fails if ... // $dir is not a directory if ( !is_dir( $dir ) ) return false; // rootCheck is enabled and $dir is not part of the root directory if ( $rootCheck && strpos( dirname( realpath( $dir ) ) . DIRECTORY_SEPARATOR, realpath( eZSys::rootDir() ) . DIRECTORY_SEPARATOR ) === false ) return false; // the directory cannot be opened if ( ! ( $handle = @opendir( $dir ) ) ) return false; while ( ( $file = readdir( $handle ) ) !== false ) { if ( ( $file == "." ) || ( $file == ".." ) ) { continue; } if ( is_dir( $dir . '/' . $file ) ) { eZDir::recursiveDelete( $dir . '/' . $file, false ); } else { unlink( $dir . '/' . $file ); } } @closedir( $handle ); return rmdir( $dir ); }
/** * Deletes specified file/directory. * * If a directory specified it is deleted recursively. * * \public * \static */ function delete() { $path = $this->filePath; eZDebugSetting::writeDebug('kernel-clustering', "fs::delete( '{$path}' )", __METHOD__); eZDebug::accumulatorStart('dbfile', false, 'dbfile'); if (is_file($path)) { $handler = eZFileHandler::instance(false); $handler->unlink($path); if (file_exists($path)) { eZDebug::writeError("File still exists after removal: '{$path}'", __METHOD__); } } elseif (is_dir($path)) { eZDir::recursiveDelete($path); } eZClusterFileHandler::cleanupEmptyDirectories($path); $this->loadMetaData(true); eZDebug::accumulatorStop('dbfile'); }
/** * Tests the stalecache behaviour through processCache() */ public function testStaleCache() { eZDir::recursiveDelete('var/tests/' . __FUNCTION__); $i = 0; $path = 'var/tests/' . __FUNCTION__ . '/cache.txt'; $content = array(__METHOD__, 2, 3, 4); $newContent = array(__METHOD__, 5, 6, 7); $extradata = array('content' => $content); // Create the cache item, and expire it $ch = eZClusterFileHandler::instance($path); $result = $ch->processCache(array($this, 'processCacheRetrieveCallback'), array($this, 'processCacheGenerateCallback'), null, null, $extradata); $ch->loadMetaData(true); self::assertEquals($extradata['content'], $result); self::assertTrue($ch->exists(), "Cache file '{$path}' doesn't exist"); $ch->delete(); $ch->loadMetaData(true); // Re-process the deleted item without a generate callback (stay in generation mode) $chGenerate = eZClusterFileHandler::instance($path); $result = $chGenerate->processCache(array($this, 'processCacheRetrieveCallback'), null, null, null, $extradata); self::assertNotEquals($content, $result, "Generation start"); self::assertInstanceOf('eZClusterFileFailure', $result, "Generation start"); $chGenerate->abortCacheGeneration(); // call the same function another time to trigger stalecache $ch = eZClusterFileHandler::instance($path); $result = $ch->processCache(array($this, 'processCacheRetrieveCallback'), array($this, 'processCacheGenerateCallback'), null, null, $extradata); self::assertEquals($content, $result, "Stalecache content"); // delete the local cache file to trigger DB based stale cache $ch->deleteLocal(); clearstatcache($path); $result = $ch->processCache(array($this, 'processCacheRetrieveCallback'), array($this, 'processCacheGenerateCallback'), null, null, $extradata); self::assertEquals($content, $result, "Stalecache content"); unset($ch); // store the new cache contents $chGenerate->storeCache(self::processCacheGenerateCallback($path, array('content' => $newContent))); $chGenerate->loadMetaData(true); unset($chGenerate); // re-request the cache a last time and check that it matches the new content $ch = eZClusterFileHandler::instance($path); $result = $ch->processCache(array($this, 'processCacheRetrieveCallback'), array($this, 'processCacheGenerateCallback'), null, null, $extradata); self::assertEquals($newContent, $result, "New content"); unset($ch); // re-request the cache after making the local file expire (make it older) $ch = eZClusterFileHandler::instance($path); touch($path, strtotime('-1 hour')); clearstatcache($path); $result = $ch->processCache(array($this, 'processCacheRetrieveCallback'), array($this, 'processCacheGenerateCallback'), null, null, $extradata); self::assertEquals($newContent, $result, "New content"); unset($ch); /* This test isn't really useful: we delete the local & DB file, and will of course end-up waiting for the generation to be finished Possibilities: - 'generate' mode instead of a 'wait' one - reduce the timeout to a few seconds, and check that the wait has occured */ /*// expire cache completely again $ch = eZClusterFileHandler::instance( $path ); $ch->delete(); $ch->purge(); $ch->loadMetaData( true ); self::assertFalse( $ch->exists(), "Cache file exists #3" ); unset( $ch ); // re-process it without a generate callback (stay in generation mode) $chGenerate = eZClusterFileHandler::instance( $path ); $result = $chGenerate->processCache( array( $this, 'processCacheRetrieveCallback' ), null, null, null, $extradata ); self::assertNotEquals( $content, $result, "Generation start" ); self::assertInstanceOf( 'eZClusterFileFailure', $result, "Generation start" ); // call the same function another time to trigger stalecache $ch = eZClusterFileHandler::instance( $path ); $result = $ch->processCache( array( $this, 'processCacheRetrieveCallback' ), array( $this, 'processCacheGenerateCallback' ), null, null, $extradata ); self::assertEquals( $content, $result, "Stalecache content" ); // store the new cache contents $chGenerate->storeCache( self::processCacheGenerateCallback( $path, array('content' => $newContent ) ) ); $chGenerate->loadMetaData( true ); unset( $chGenerate );*/ self::deleteLocalFiles($path); }
} if (count($missingFileList) > 0 or count($exportMissingFileList) > 0 or count($fileList) > 0 or count($conflictFileList) > 0) { if (count($fileList) > 0) { foreach ($fileList as $file) { print '? ' . $file . "\n"; } } if (count($missingFileList) > 0) { foreach ($missingFileList as $file) { print '! ' . $file . "\n"; } } if (count($exportMissingFileList) > 0) { foreach ($exportMissingFileList as $file) { print 'A ' . $file . "\n"; } } if (count($conflictFileList) > 0) { foreach ($conflictFileList as $file) { print 'C ' . $file . "\n"; } } $script->setExitCode(1); } if (!$options['no-verify-branches']) { // Cleanup any exports if (file_exists($exportPath)) { eZDir::recursiveDelete($exportPath, false); } } $script->shutdown();
public function setUp() { eZDir::recursiveDelete(eZINI::instance()->variable('FileSettings', 'VarDir')); }