/**
  * Field post-processing hook for the process_datamap() method.
  *
  * @access	public
  *
  * @param	string		$status: 'new' or 'update'
  * @param	string		$table: The destination table
  * @param	integer		$id: The uid of the record
  * @param	array		&$fieldArray: Array of field values
  * @param	\TYPO3\CMS\Core\DataHandling\DataHandler $pObj: The parent object
  *
  * @return	void
  */
 public function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, $pObj)
 {
     if ($status == 'new') {
         switch ($table) {
             // Field post-processing for table "tx_dlf_documents".
             case 'tx_dlf_documents':
                 // Set sorting field if empty.
                 if (empty($fieldArray['title_sorting']) && !empty($fieldArray['title'])) {
                     $fieldArray['title_sorting'] = $fieldArray['title'];
                 }
                 break;
                 // Field post-processing for table "tx_dlf_metadata".
             // Field post-processing for table "tx_dlf_metadata".
             case 'tx_dlf_metadata':
                 // Store field in index if it should appear in lists.
                 if (!empty($fieldArray['is_listed'])) {
                     $fieldArray['stored'] = 1;
                 }
                 // Index field in index if it should be used for auto-completion.
                 if (!empty($fieldArray['autocomplete'])) {
                     $fieldArray['indexed'] = 1;
                 }
                 // Field post-processing for tables "tx_dlf_metadata", "tx_dlf_collections", "tx_dlf_libraries" and "tx_dlf_structures".
             // Field post-processing for tables "tx_dlf_metadata", "tx_dlf_collections", "tx_dlf_libraries" and "tx_dlf_structures".
             case 'tx_dlf_collections':
             case 'tx_dlf_libraries':
             case 'tx_dlf_structures':
                 // Set label as index name if empty.
                 if (empty($fieldArray['index_name']) && !empty($fieldArray['label'])) {
                     $fieldArray['index_name'] = $fieldArray['label'];
                 }
                 // Set index name as label if empty.
                 if (empty($fieldArray['label']) && !empty($fieldArray['index_name'])) {
                     $fieldArray['label'] = $fieldArray['index_name'];
                 }
                 // Ensure that index names don't get mixed up with sorting values.
                 if (substr($fieldArray['index_name'], -8) == '_sorting') {
                     $fieldArray['index_name'] .= '0';
                 }
                 break;
                 // Field post-processing for table "tx_dlf_solrcores".
             // Field post-processing for table "tx_dlf_solrcores".
             case 'tx_dlf_solrcores':
                 // Get number of existing cores.
                 $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_dlf_solrcores', '', '', '', '');
                 // Get first unused core number.
                 $coreNumber = tx_dlf_solr::solrGetCoreNumber($GLOBALS['TYPO3_DB']->sql_num_rows($result));
                 // Get Solr credentials.
                 $conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dlf']);
                 // Prepend username and password to hostname.
                 if ($conf['solrUser'] && $conf['solrPass']) {
                     $host = $conf['solrUser'] . ':' . $conf['solrPass'] . '@' . ($conf['solrHost'] ? $conf['solrHost'] : 'localhost');
                 } else {
                     $host = $conf['solrHost'] ? $conf['solrHost'] : 'localhost';
                 }
                 // Set port if not set.
                 $port = intval($conf['solrPort']) > 0 ? intval($conf['solrPort']) : 8180;
                 // Trim path and append trailing slash.
                 $path = trim($conf['solrPath'], '/') ? trim($conf['solrPath'], '/') . '/' : '';
                 $context = stream_context_create(array('http' => array('method' => 'GET', 'user_agent' => $conf['useragent'] ? $conf['useragent'] : ini_get('user_agent'))));
                 // Build request for adding new Solr core.
                 // @see http://wiki.apache.org/solr/CoreAdmin
                 $url = 'http://' . $host . ':' . $port . '/' . $path . 'admin/cores?action=CREATE&name=dlfCore' . $coreNumber . '&instanceDir=.&dataDir=dlfCore' . $coreNumber;
                 $response = @simplexml_load_string(file_get_contents($url, FALSE, $context));
                 // Process response.
                 if ($response) {
                     $status = $response->xpath('//lst[@name="responseHeader"]/int[@name="status"]');
                     if ($status && $status[0] == 0) {
                         $fieldArray['index_name'] = 'dlfCore' . $coreNumber;
                         return;
                     }
                 }
                 if (TYPO3_DLOG) {
                     \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_tcemain->processDatamap_postProcessFieldArray(' . $status . ', ' . $table . ', ' . $id . ', [data], [' . get_class($pObj) . '])] Could not create new Apache Solr core "dlfCore' . $coreNumber . '"', $this->extKey, SYSLOG_SEVERITY_ERROR, $fieldArray);
                 }
                 // Solr core could not be created, thus unset field array.
                 $fieldArray = array();
                 break;
         }
     } elseif ($status == 'update') {
         switch ($table) {
             // Field post-processing for table "tx_dlf_metadata".
             case 'tx_dlf_metadata':
                 // Store field in index if it should appear in lists.
                 if (!empty($fieldArray['is_listed'])) {
                     $fieldArray['stored'] = 1;
                 }
                 if (isset($fieldArray['stored']) && $fieldArray['stored'] == 0 && !isset($fieldArray['is_listed'])) {
                     // Get current configuration.
                     $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery($table . '.is_listed AS is_listed', $table, $table . '.uid=' . intval($id) . tx_dlf_helper::whereClause($table), '', '', '1');
                     if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
                         // Reset storing to current.
                         list($fieldArray['stored']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
                     }
                 }
                 // Index field in index if it should be used for auto-completion.
                 if (!empty($fieldArray['autocomplete'])) {
                     $fieldArray['indexed'] = 1;
                 }
                 if (isset($fieldArray['indexed']) && $fieldArray['indexed'] == 0 && !isset($fieldArray['autocomplete'])) {
                     // Get current configuration.
                     $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery($table . '.autocomplete AS autocomplete', $table, $table . '.uid=' . intval($id) . tx_dlf_helper::whereClause($table), '', '', '1');
                     if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
                         // Reset indexing to current.
                         list($fieldArray['indexed']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
                     }
                 }
                 // Field post-processing for tables "tx_dlf_metadata" and "tx_dlf_structures".
             // Field post-processing for tables "tx_dlf_metadata" and "tx_dlf_structures".
             case 'tx_dlf_structures':
                 // The index name should not be changed in production.
                 if (isset($fieldArray['index_name'])) {
                     if (count($fieldArray) < 2) {
                         // Unset the whole field array.
                         $fieldArray = array();
                     } else {
                         // Get current index name.
                         $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery($table . '.index_name AS index_name', $table, $table . '.uid=' . intval($id) . tx_dlf_helper::whereClause($table), '', '', '1');
                         if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
                             // Reset index name to current.
                             list($fieldArray['index_name']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
                         }
                     }
                     if (TYPO3_DLOG) {
                         \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('[tx_dlf_tcemain->processDatamap_postProcessFieldArray(' . $status . ', ' . $table . ', ' . $id . ', [data], [' . get_class($pObj) . '])] Prevented change of "index_name" for UID "' . $id . '" in table "' . $table . '"', $this->extKey, SYSLOG_SEVERITY_NOTICE, $fieldArray);
                     }
                 }
                 break;
         }
     }
 }