public function search($searchText, $params = array(), $searchTypes = array())
 {
     if (count($searchTypes) == 0) {
         $searchTypes['general'] = array();
         $searchTypes['subtype'] = array();
         $searchTypes['and'] = array();
     } else {
         if (!isset($searchTypes['general'])) {
             $searchTypes['general'] = array();
         }
     }
     $allowSearch = true;
     if (trim($searchText) == '') {
         $ini = eZINI::instance();
         if ($ini->variable('SearchSettings', 'AllowEmptySearch') != 'enabled') {
             $allowSearch = false;
         }
         if (isset($params['AllowEmptySearch'])) {
             $allowSearch = $params['AllowEmptySearch'];
         }
     }
     if ($allowSearch) {
         $searchText = $this->normalizeText($searchText, false);
         $db = eZDB::instance();
         $nonExistingWordArray = array();
         $searchTypeMap = array('class' => 'SearchContentClassID', 'publishdate' => 'SearchDate', 'subtree' => 'SearchSubTreeArray');
         foreach ($searchTypes['general'] as $searchType) {
             $params[$searchTypeMap[$searchType['subtype']]] = $searchType['value'];
         }
         if (isset($params['SearchOffset'])) {
             $searchOffset = $params['SearchOffset'];
         } else {
             $searchOffset = 0;
         }
         if (isset($params['SearchLimit'])) {
             $searchLimit = $params['SearchLimit'];
         } else {
             $searchLimit = 10;
         }
         if (isset($params['SearchContentClassID'])) {
             $searchContentClassID = $params['SearchContentClassID'];
         } else {
             $searchContentClassID = -1;
         }
         if (isset($params['SearchSectionID'])) {
             $searchSectionID = $params['SearchSectionID'];
         } else {
             $searchSectionID = -1;
         }
         if (isset($params['SearchDate'])) {
             $searchDate = $params['SearchDate'];
         } else {
             $searchDate = -1;
         }
         if (isset($params['SearchTimestamp'])) {
             $searchTimestamp = $params['SearchTimestamp'];
         } else {
             $searchTimestamp = false;
         }
         if (isset($params['SearchContentClassAttributeID'])) {
             $searchContentClassAttributeID = $params['SearchContentClassAttributeID'];
         } else {
             $searchContentClassAttributeID = -1;
         }
         if (isset($params['SearchSubTreeArray'])) {
             $subTreeArray = $params['SearchSubTreeArray'];
         } else {
             $subTreeArray = array();
         }
         if (isset($params['SortArray'])) {
             $sortArray = $params['SortArray'];
         } else {
             $sortArray = array();
         }
         $ignoreVisibility = isset($params['IgnoreVisibility']) ? $params['IgnoreVisibility'] : false;
         // strip multiple spaces
         $searchText = preg_replace("(\\s+)", " ", $searchText);
         // find the phrases
         /*            $numQuotes = substr_count( $searchText, "\"" );
         
                     $phraseTextArray = array();
                     $fullText = $searchText;
                     $nonPhraseText ='';
         //            $fullText = '';
                     $postPhraseText = $fullText;
                     $pos = 0;
                     if ( ( $numQuotes > 0 ) and ( ( $numQuotes % 2 ) == 0 ) )
                     {
                         for ( $i = 0; $i < ( $numQuotes / 2 ); $i ++ )
                         {
                             $quotePosStart = strpos( $searchText, '"',  $pos );
                             $quotePosEnd = strpos( $searchText, '"',  $quotePosStart + 1 );
         
                             $prePhraseText = substr( $searchText, $pos, $quotePosStart - $pos );
                             $postPhraseText = substr( $searchText, $quotePosEnd +1 );
                             $phraseText = substr( $searchText, $quotePosStart + 1, $quotePosEnd - $quotePosStart - 1 );
         
                             $phraseTextArray[] = $phraseText;
         //                    $fullText .= $prePhraseText;
                             $nonPhraseText .= $prePhraseText;
                             $pos = $quotePosEnd + 1;
                         }
                     }
                     $nonPhraseText .= $postPhraseText;
         */
         $phrasesResult = $this->getPhrases($searchText);
         $phraseTextArray = $phrasesResult['phrases'];
         $nonPhraseText = $phrasesResult['nonPhraseText'];
         $fullText = $phrasesResult['fullText'];
         $sectionQuery = '';
         if (is_numeric($searchSectionID) and $searchSectionID > 0) {
             $sectionQuery = "ezsearch_object_word_link.section_id = '{$searchSectionID}' AND ";
         } else {
             if (is_array($searchSectionID)) {
                 // Build query for searching in an array of sections
                 $sectionQuery = $db->generateSQLINStatement($searchSectionID, 'ezsearch_object_word_link.section_id', false, false, 'int') . " AND ";
             }
         }
         $searchDateQuery = '';
         if (is_numeric($searchDate) and $searchDate > 0 or $searchTimestamp) {
             $date = new eZDateTime();
             $timestamp = $date->timeStamp();
             $day = $date->attribute('day');
             $month = $date->attribute('month');
             $year = $date->attribute('year');
             $publishedDateStop = false;
             if ($searchTimestamp) {
                 if (is_array($searchTimestamp)) {
                     $publishedDate = (int) $searchTimestamp[0];
                     $publishedDateStop = (int) $searchTimestamp[1];
                 } else {
                     $publishedDate = (int) $searchTimestamp;
                 }
             } else {
                 switch ($searchDate) {
                     case 1:
                         $adjustment = 24 * 60 * 60;
                         //seconds for one day
                         $publishedDate = $timestamp - $adjustment;
                         break;
                     case 2:
                         $adjustment = 7 * 24 * 60 * 60;
                         //seconds for one week
                         $publishedDate = $timestamp - $adjustment;
                         break;
                     case 3:
                         $adjustment = 31 * 24 * 60 * 60;
                         //seconds for one month
                         $publishedDate = $timestamp - $adjustment;
                         break;
                     case 4:
                         $adjustment = 3 * 31 * 24 * 60 * 60;
                         //seconds for three months
                         $publishedDate = $timestamp - $adjustment;
                         break;
                     case 5:
                         $adjustment = 365 * 24 * 60 * 60;
                         //seconds for one year
                         $publishedDate = $timestamp - $adjustment;
                         break;
                     default:
                         $publishedDate = $date->timeStamp();
                 }
             }
             $searchDateQuery = "ezsearch_object_word_link.published >= '{$publishedDate}' AND ";
             if ($publishedDateStop) {
                 $searchDateQuery .= "ezsearch_object_word_link.published <= '{$publishedDateStop}' AND ";
             }
             $this->GeneralFilter['searchDateQuery'] = $searchDateQuery;
         }
         $classQuery = "";
         if (is_numeric($searchContentClassID) and $searchContentClassID > 0) {
             // Build query for searching in one class
             $classQuery = "ezsearch_object_word_link.contentclass_id = '{$searchContentClassID}' AND ";
             $this->GeneralFilter['classAttributeQuery'] = $classQuery;
         } else {
             if (is_array($searchContentClassID)) {
                 // Build query for searching in a number of classes
                 $classString = $db->generateSQLINStatement($searchContentClassID, 'ezsearch_object_word_link.contentclass_id', false, false, 'int');
                 $classQuery = "{$classString} AND ";
                 $this->GeneralFilter['classAttributeQuery'] = $classQuery;
             }
         }
         $classAttributeQuery = "";
         if (is_numeric($searchContentClassAttributeID) and $searchContentClassAttributeID > 0) {
             $classAttributeQuery = "ezsearch_object_word_link.contentclass_attribute_id = '{$searchContentClassAttributeID}' AND ";
         } else {
             if (is_array($searchContentClassAttributeID)) {
                 // Build query for searching in a number of attributes
                 $classAttributeQuery = $db->generateSQLINStatement($searchContentClassAttributeID, 'ezsearch_object_word_link.contentclass_attribute_id', false, false, 'int') . ' AND ';
             }
         }
         // Get the total number of objects
         $totalObjectCount = $this->fetchTotalObjectCount();
         $searchPartsArray = array();
         $wordIDHash = array();
         $wildCardCount = 0;
         if (trim($searchText) != '') {
             $wordIDArrays = $this->prepareWordIDArrays($searchText);
             $wordIDArray = $wordIDArrays['wordIDArray'];
             $wordIDHash = $wordIDArrays['wordIDHash'];
             $wildIDArray = $wordIDArrays['wildIDArray'];
             $wildCardCount = $wordIDArrays['wildCardCount'];
             $searchPartsArray = $this->buildSearchPartArray($phraseTextArray, $nonPhraseText, $wordIDHash, $wildIDArray);
         }
         /// OR search, not used in this version
         $doOrSearch = false;
         if ($doOrSearch == true) {
             // build fulltext search SQL part
             $searchWordArray = $this->splitString($fullText);
             $fullTextSQL = "";
             if (count($searchWordArray) > 0) {
                 $i = 0;
                 // Build the word query string
                 foreach ($searchWordArray as $searchWord) {
                     $wordID = null;
                     if (isset($wordIDHash[$searchWord])) {
                         $wordID = $wordIDHash[$searchWord]['id'];
                     }
                     if (is_numeric($wordID) and $wordID > 0) {
                         if ($i == 0) {
                             $fullTextSQL .= "ezsearch_object_word_link.word_id='{$wordID}' ";
                         } else {
                             $fullTextSQL .= " OR ezsearch_object_word_link.word_id='{$wordID}' ";
                         }
                     } else {
                         $nonExistingWordArray[] = $searchWord;
                     }
                     $i++;
                 }
                 $fullTextSQL = " ( {$fullTextSQL} ) AND ";
             }
         }
         // Search only in specific sub trees
         $subTreeSQL = "";
         $subTreeTable = "";
         if (count($subTreeArray) > 0) {
             // Fetch path_string value to use when searching subtrees
             $i = 0;
             $doSubTreeSearch = false;
             $subTreeNodeSQL = '';
             foreach ($subTreeArray as $nodeID) {
                 if (is_numeric($nodeID) and $nodeID > 0) {
                     $subTreeNodeSQL .= " {$nodeID}";
                     if (isset($subTreeArray[$i + 1]) and is_numeric($subTreeArray[$i + 1])) {
                         $subTreeNodeSQL .= ", ";
                     }
                     $doSubTreeSearch = true;
                 }
                 $i++;
             }
             if ($doSubTreeSearch == true) {
                 $subTreeNodeSQL = "( " . $subTreeNodeSQL;
                 //                    $subTreeTable = ", ezcontentobject_tree ";
                 $subTreeTable = '';
                 $subTreeNodeSQL .= " ) ";
                 $nodeQuery = "SELECT node_id, path_string FROM ezcontentobject_tree WHERE node_id IN {$subTreeNodeSQL}";
                 // Build SQL subtre search query
                 $subTreeSQL = " ( ";
                 $nodeArray = $db->arrayQuery($nodeQuery);
                 $i = 0;
                 foreach ($nodeArray as $node) {
                     $pathString = $node['path_string'];
                     $subTreeSQL .= " ezcontentobject_tree.path_string like '{$pathString}%' ";
                     if ($i < count($nodeArray) - 1) {
                         $subTreeSQL .= " OR ";
                     }
                     $i++;
                 }
                 $subTreeSQL .= " ) AND ";
                 $this->GeneralFilter['subTreeTable'] = $subTreeTable;
                 $this->GeneralFilter['subTreeSQL'] = $subTreeSQL;
             }
         }
         $limitation = false;
         if (isset($params['Limitation'])) {
             $limitation = $params['Limitation'];
         }
         $limitationList = eZContentObjectTreeNode::getLimitationList($limitation);
         $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList);
         $this->GeneralFilter['sqlPermissionChecking'] = $sqlPermissionChecking;
         $versionNameJoins = " AND " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject');
         /// Only support AND search at this time
         // build fulltext search SQL part
         $searchWordArray = $this->splitString($fullText);
         $searchWordCount = count($searchWordArray);
         $fullTextSQL = "";
         $stopWordArray = array();
         $ini = eZINI::instance();
         $tmpTableCount = 0;
         $i = 0;
         foreach ($searchTypes['and'] as $searchType) {
             $methodName = $this->constructMethodName($searchType);
             $intermediateResult = $this->callMethod($methodName, array($searchType));
             if ($intermediateResult == false) {
                 // cleanup temp tables
                 $db->dropTempTableList($sqlPermissionChecking['temp_tables']);
                 return array("SearchResult" => array(), "SearchCount" => 0, "StopWordArray" => array());
             }
         }
         // Do not execute search if site.ini:[SearchSettings]->AllowEmptySearch is enabled, but no conditions are set.
         if (!$searchDateQuery && !$sectionQuery && !$classQuery && !$classAttributeQuery && !$searchPartsArray && !$subTreeSQL) {
             // cleanup temp tables
             $db->dropTempTableList($sqlPermissionChecking['temp_tables']);
             return array("SearchResult" => array(), "SearchCount" => 0, "StopWordArray" => array());
         }
         $i = $this->TempTablesCount;
         // Loop every word and insert result in temporary table
         // Determine whether we should search invisible nodes.
         $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(!$ignoreVisibility);
         foreach ($searchPartsArray as $searchPart) {
             $stopWordThresholdValue = 100;
             if ($ini->hasVariable('SearchSettings', 'StopWordThresholdValue')) {
                 $stopWordThresholdValue = $ini->variable('SearchSettings', 'StopWordThresholdValue');
             }
             $stopWordThresholdPercent = 60;
             if ($ini->hasVariable('SearchSettings', 'StopWordThresholdPercent')) {
                 $stopWordThresholdPercent = $ini->variable('SearchSettings', 'StopWordThresholdPercent');
             }
             $searchThresholdValue = $totalObjectCount;
             if ($totalObjectCount > $stopWordThresholdValue) {
                 $searchThresholdValue = (int) ($totalObjectCount * ($stopWordThresholdPercent / 100));
             }
             // do not search words that are too frequent
             if ($searchPart['object_count'] < $searchThresholdValue) {
                 $tmpTableCount++;
                 $searchPartText = $searchPart['sql_part'];
                 if ($i == 0) {
                     $table = $db->generateUniqueTempTableName('ezsearch_tmp_%', 0);
                     $this->saveCreatedTempTableName(0, $table);
                     $db->createTempTable("CREATE TEMPORARY TABLE {$table} ( contentobject_id int primary key not null, published int )");
                     $db->query("INSERT INTO {$table} SELECT DISTINCT ezsearch_object_word_link.contentobject_id, ezsearch_object_word_link.published\n                                         FROM ezcontentobject\n                                              INNER JOIN ezsearch_object_word_link ON (ezsearch_object_word_link.contentobject_id = ezcontentobject.id)\n                                              {$subTreeTable}\n                                              INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n                                              INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n                                              {$sqlPermissionChecking['from']}\n                                         WHERE\n                                               {$searchDateQuery}\n                                               {$sectionQuery}\n                                               {$classQuery}\n                                               {$classAttributeQuery}\n                                               {$searchPartText}\n                                               {$subTreeSQL}\n                                         ezcontentclass.version = '0' AND\n                                         ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id\n                                         {$showInvisibleNodesCond}\n                                         {$sqlPermissionChecking['where']}", eZDBInterface::SERVER_SLAVE);
                 } else {
                     $table = $db->generateUniqueTempTableName('ezsearch_tmp_%', $i);
                     $this->saveCreatedTempTableName($i, $table);
                     $tmpTable0 = $this->getSavedTempTableName(0);
                     $db->createTempTable("CREATE TEMPORARY TABLE {$table} ( contentobject_id int primary key not null, published int )");
                     $db->query("INSERT INTO {$table} SELECT DISTINCT ezsearch_object_word_link.contentobject_id, ezsearch_object_word_link.published\n                                         FROM\n                                             ezcontentobject\n                                             INNER JOIN ezsearch_object_word_link ON (ezsearch_object_word_link.contentobject_id = ezcontentobject.id)\n                                             {$subTreeTable}\n                                             INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n                                             INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n                                             INNER JOIN {$tmpTable0} ON ({$tmpTable0}.contentobject_id = ezsearch_object_word_link.contentobject_id)\n                                             {$sqlPermissionChecking['from']}\n                                          WHERE\n                                          {$searchDateQuery}\n                                          {$sectionQuery}\n                                          {$classQuery}\n                                          {$classAttributeQuery}\n                                          {$searchPartText}\n                                          {$subTreeSQL}\n                                          ezcontentclass.version = '0' AND\n                                          ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id\n                                          {$showInvisibleNodesCond}\n                                          {$sqlPermissionChecking['where']}", eZDBInterface::SERVER_SLAVE);
                 }
                 $i++;
             } else {
                 $stopWordArray[] = array('word' => $searchPart['text']);
             }
         }
         if (count($searchPartsArray) === 0 && $this->TempTablesCount == 0) {
             $table = $db->generateUniqueTempTableName('ezsearch_tmp_%', 0);
             $this->saveCreatedTempTableName(0, $table);
             $db->createTempTable("CREATE TEMPORARY TABLE {$table} ( contentobject_id int primary key not null, published int )");
             $db->query("INSERT INTO {$table} SELECT DISTINCT ezsearch_object_word_link.contentobject_id, ezsearch_object_word_link.published\n                                     FROM ezcontentobject\n                                          INNER JOIN ezsearch_object_word_link ON (ezsearch_object_word_link.contentobject_id = ezcontentobject.id)\n                                          {$subTreeTable}\n                                          INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id)\n                                          INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n                                          {$sqlPermissionChecking['from']}\n                                     WHERE\n                                          {$searchDateQuery}\n                                          {$sectionQuery}\n                                          {$classQuery}\n                                          {$classAttributeQuery}\n                                          {$subTreeSQL}\n                                          ezcontentclass.version = '0' AND\n                                          ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id\n                                          {$showInvisibleNodesCond}\n                                          {$sqlPermissionChecking['where']}", eZDBInterface::SERVER_SLAVE);
             $this->TempTablesCount = 1;
             $i = $this->TempTablesCount;
         }
         $nonExistingWordCount = count(array_unique($searchWordArray)) - count($wordIDHash) - $wildCardCount;
         $excludeWordCount = $searchWordCount - count($stopWordArray);
         if (count($stopWordArray) + $nonExistingWordCount == $searchWordCount && $this->TempTablesCount == 0) {
             // No words to search for, return empty result
             // cleanup temp tables
             $db->dropTempTableList($sqlPermissionChecking['temp_tables']);
             $db->dropTempTableList($this->getSavedTempTablesList());
             return array("SearchResult" => array(), "SearchCount" => 0, "StopWordArray" => $stopWordArray);
         }
         $tmpTablesFrom = "";
         $tmpTablesWhere = "";
         /// tmp tables
         $tmpTableCount = $i;
         for ($i = 0; $i < $tmpTableCount; $i++) {
             $tmpTablesFrom .= $this->getSavedTempTableName($i);
             if ($i < $tmpTableCount - 1) {
                 $tmpTablesFrom .= ", ";
             }
         }
         $tmpTablesSeparator = '';
         if ($tmpTableCount > 0) {
             $tmpTablesSeparator = ', ';
         }
         $tmpTable0 = $this->getSavedTempTableName(0);
         for ($i = 1; $i < $tmpTableCount; $i++) {
             $tmpTableI = $this->getSavedTempTableName($i);
             $tmpTablesWhere .= " {$tmpTable0}.contentobject_id={$tmpTableI}.contentobject_id  ";
             if ($i < $tmpTableCount - 1) {
                 $tmpTablesWhere .= " AND ";
             }
         }
         $tmpTablesWhereExtra = '';
         if ($tmpTableCount > 0) {
             $tmpTablesWhereExtra = "ezcontentobject.id={$tmpTable0}.contentobject_id AND";
         }
         $and = "";
         if ($tmpTableCount > 1) {
             $and = " AND ";
         }
         // Generate ORDER BY SQL
         $orderBySQLArray = $this->buildSortSQL($sortArray);
         $orderByFieldsSQL = $orderBySQLArray['sortingFields'];
         $sortWhereSQL = $orderBySQLArray['whereSQL'];
         $sortFromSQL = $orderBySQLArray['fromSQL'];
         $sortSelectSQL = $orderBySQLArray['selectSQL'];
         // Fetch data from table
         $searchQuery = '';
         $searchQuery = "SELECT DISTINCT ezcontentobject.*, ezcontentclass.serialized_name_list as class_serialized_name_list,\n                ezcontentobject_tree.*, ezcontentobject_name.name as name,\n                ezcontentobject_name.real_translation {$sortSelectSQL}\n                FROM\n                   {$tmpTablesFrom} {$tmpTablesSeparator}\n                   ezcontentobject\n                   INNER JOIN ezcontentclass ON (ezcontentclass.id = ezcontentobject.contentclass_id )\n                   INNER JOIN ezcontentobject_tree ON (ezcontentobject_tree.contentobject_id = ezcontentobject.id)\n                   INNER JOIN ezcontentobject_name ON (\n                       ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND\n                       ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version\n                   )\n                   {$sortFromSQL}\n                WHERE\n                {$tmpTablesWhere} {$and}\n                {$tmpTablesWhereExtra}\n                ezcontentclass.version = '0' AND\n                ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id AND\n                " . eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject') . "\n                {$showInvisibleNodesCond}\n                {$sortWhereSQL}\n                ORDER BY {$orderByFieldsSQL}";
         // Count query
         $languageCond = eZContentLanguage::languagesSQLFilter('ezcontentobject');
         if ($tmpTableCount == 0) {
             $searchCountQuery = "SELECT count( DISTINCT ezcontentobject.id ) AS count\n                        FROM\n                           ezcontentobject,\n                           ezcontentobject_tree\n                        WHERE\n                        ezcontentobject.id = ezcontentobject_tree.contentobject_id and\n                        ezcontentobject_tree.node_id = ezcontentobject_tree.main_node_id\n                        AND {$languageCond}\n                        {$showInvisibleNodesCond}";
         } else {
             $searchCountQuery = "SELECT count( DISTINCT ezcontentobject.id ) AS count\n                        FROM {$tmpTablesFrom} {$tmpTablesSeparator}\n                             ezcontentobject\n                        WHERE {$tmpTablesWhere} {$and}\n                            {$tmpTablesWhereExtra}\n                            {$languageCond}";
         }
         $objectRes = array();
         $searchCount = 0;
         if ($nonExistingWordCount <= 0) {
             // execute search query
             $objectResArray = $db->arrayQuery($searchQuery, array("limit" => $searchLimit, "offset" => $searchOffset), eZDBInterface::SERVER_SLAVE);
             // execute search count query
             $objectCountRes = $db->arrayQuery($searchCountQuery, array(), eZDBInterface::SERVER_SLAVE);
             $objectRes = eZContentObjectTreeNode::makeObjectsArray($objectResArray);
             $searchCount = $objectCountRes[0]['count'];
         } else {
             $objectRes = array();
         }
         // Drop tmp tables
         $db->dropTempTableList($sqlPermissionChecking['temp_tables']);
         $db->dropTempTableList($this->getSavedTempTablesList());
         return array("SearchResult" => $objectRes, "SearchCount" => $searchCount, "StopWordArray" => $stopWordArray);
     } else {
         return array("SearchResult" => array(), "SearchCount" => 0, "StopWordArray" => array());
     }
 }
        $scriptFile = $scriptDirectory . '/' . $cronScript;
        if (file_exists($scriptFile)) {
            break;
        }
    }
    if (file_exists($scriptFile)) {
        if ($index > 0) {
            $cli->output();
        }
        if (!$isQuiet) {
            $startTime = new eZDateTime();
            $cli->output('Running ' . $cli->stylize('emphasize', $scriptFile) . ' at: ' . $startTime->toString(true));
        }
        eZDebug::addTimingPoint("Script {$scriptFile} starting");
        eZRunCronjobs::runScript($cli, $scriptFile);
        eZDebug::addTimingPoint("Script {$scriptFile} done");
        ++$index;
        // The transaction check
        $transactionCounterCheck = eZDB::checkTransactionCounter();
        if (isset($transactionCounterCheck['error'])) {
            $cli->error($transactionCounterCheck['error']);
        }
        if (!$isQuiet) {
            $endTime = new eZDateTime();
            $cli->output('Completing ' . $cli->stylize('emphasize', $scriptFile) . ' at: ' . $endTime->toString(true));
            $elapsedTime = new eZTime($endTime->timeStamp() - $startTime->timeStamp());
            $cli->output('Elapsed time: ' . sprintf('%02d:%02d:%02d', $elapsedTime->hour(), $elapsedTime->minute(), $elapsedTime->second()));
        }
    }
}
$script->shutdown();
Пример #3
0
 /**
  * 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;
 }
    function batchInitializeObjectAttributeData( $classAttribute )
    {
        $defaultType = $classAttribute->attribute( self::DEFAULT_FIELD );

        switch( $defaultType )
        {
            case self::DEFAULT_CURRENT_DATE:
            {
                $default = time();
            } break;

            case self::DEFAULT_ADJUSTMENT:
            {
                $adjustments = $this->classAttributeContent( $classAttribute );
                $value = new eZDateTime();
                $secondAdjustment = $classAttribute->attribute( self::USE_SECONDS_FIELD ) == 1 ? $adjustments['second'] : 0;
                $value->adjustDateTime( $adjustments['hour'], $adjustments['minute'], $secondAdjustment, $adjustments['month'], $adjustments['day'], $adjustments['year'] );

                $default = $value->timeStamp();
            } break;

            default:
            {
                $default = 0;
            }
        }

        return array( 'data_int' => $default, 'sort_key_int' => $default );
    }
 function getTimestamp($http, $id)
 {
     $day = $http->postVariable('newsletter_datetime_day_' . $id);
     $month = $http->postVariable('newsletter_datetime_month_' . $id);
     $year = $http->postVariable('newsletter_datetime_year_' . $id);
     $hour = $http->postVariable('newsletter_datetime_hour_' . $id);
     $minute = $http->postVariable('newsletter_datetime_minute_' . $id);
     $dateTime = new eZDateTime();
     if ($year == '' and $month == '' and $day == '' and $hour == '' and $minute == '' or !checkdate($month, $day, $year) or $year < 1970) {
         $dateTime->setTimeStamp(0);
     } else {
         $dateTime->setMDYHMS($month, $day, $year, $hour, $minute, 0);
     }
     return $dateTime->timeStamp();
 }