Fix Bug #1049844: MySQL's max_allowed_packet must eventually be raised

This commit is contained in:
Sebastian Meyer 2013-09-08 21:52:43 +02:00
parent 3cfdb185d8
commit d1de47145f
8 changed files with 281 additions and 188 deletions

View File

@ -719,7 +719,6 @@ class tx_dlf_indexing {
}
/**
* This is a static class, thus no instances should be created
*

View File

@ -27,7 +27,7 @@
*/
/**
* Document class 'tx_dlf_list' for the 'dlf' extension.
* List class 'tx_dlf_list' for the 'dlf' extension.
*
* @author Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* @package TYPO3
@ -71,6 +71,30 @@ class tx_dlf_list implements ArrayAccess, Countable, Iterator, t3lib_Singleton {
*/
protected $position = 0;
/**
* This holds the full records of already processed list elements
*
* @var array()
* @access protected
*/
protected $records = array ();
/**
* Instance of Apache_Solr_Service class
*
* @var Apache_Solr_Service
* @access protected
*/
protected $solr;
/**
* This holds the Solr metadata configuration
*
* @var array
* @access protected
*/
protected $solrConfig = array ();
/**
* This adds an array of elements at the given position to the list
*
@ -145,27 +169,152 @@ class tx_dlf_list implements ArrayAccess, Countable, Iterator, t3lib_Singleton {
*
* @access protected
*
* @param array $element: The list element
* @param mixed $element: The list element
*
* @return array The element's full record
* @return mixed The element's full record
*/
protected function getRecord(array $element) {
protected function getRecord($element) {
$record = array ();
if (!empty($element['uid'])) {
if (is_array($element) && array_keys($element) == array ('u', 's', 'p')) {
// Return already processed record if possible.
if (!empty($this->records[$element['u']])) {
return $this->records[$element['u']];
}
$record = array (
'uid' => $element['u'],
'page' => 1,
'subparts' => $element['p']
);
// Check if it's a list of database records or Solr documents.
if (!empty($this->metadata['options']['source']) && $this->metadata['options']['source'] == 'collection') {
// Get document's thumbnail and metadata from database.
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_documents.uid AS uid,tx_dlf_documents.thumbnail AS thumbnail,tx_dlf_documents.metadata AS metadata',
'tx_dlf_documents',
'(tx_dlf_documents.uid='.intval($record['uid']).' OR tx_dlf_documents.partof='.intval($record['uid']).')'.tx_dlf_helper::whereClause('tx_dlf_documents'),
'',
'',
''
);
// Process results.
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
// Prepare document's metadata.
$metadata = unserialize($resArray['metadata']);
if (!empty($metadata['type'][0]) && t3lib_div::testInt($metadata['type'][0])) {
$metadata['type'][0] = tx_dlf_helper::getIndexName($metadata['type'][0], 'tx_dlf_structures', $this->metadata['options']['pid']);
}
if (!empty($metadata['owner'][0]) && t3lib_div::testInt($metadata['owner'][0])) {
$metadata['owner'][0] = tx_dlf_helper::getIndexName($metadata['owner'][0], 'tx_dlf_libraries', $this->metadata['options']['pid']);
}
if (!empty($metadata['collection']) && is_array($metadata['collection'])) {
foreach ($metadata['collection'] as $i => $collection) {
if (t3lib_div::testInt($collection)) {
$metadata['collection'][$i] = tx_dlf_helper::getIndexName($metadata['collection'][$i], 'tx_dlf_collections', $this->metadata['options']['pid']);
}
}
}
// Add metadata to list element.
if ($resArray['uid'] == $record['uid']) {
$record['thumbnail'] = $resArray['thumbnail'];
$record['metadata'] = $metadata;
} elseif (($key = array_search($resArray['uid'], $record['subparts'], TRUE)) !== FALSE) {
$record['subparts'][$key] = array (
'uid' => $resArray['uid'],
'page' => 1,
'thumbnail' => $resArray['thumbnail'],
'metadata' => $metadata,
);
}
}
} elseif (!empty($this->metadata['options']['source']) && $this->metadata['options']['source'] == 'search') {
if ($this->solrConnect()) {
// Get document's thumbnail and metadata from Solr index.
$result = $this->solr->service->search('uid:'.tx_dlf_solr::escapeQuery($record['uid']));
// Process results.
foreach ($result->response->docs as $resArray) {
// Prepare document's metadata.
$metadata = array ();
foreach ($this->solrConfig as $index_name => $solr_name) {
if (!empty($resArray->$solr_name)) {
$metadata[$index_name] = (is_array($resArray->$solr_name) ? $resArray->$solr_name : array ($resArray->$solr_name));
}
}
// Add metadata to list elements.
if ($resArray->toplevel == 1) {
$record['thumbnail'] = $resArray->thumbnail;
$record['metadata'] = $metadata;
} elseif (($key = array_search($resArray->id, $record['subparts'], TRUE)) !== FALSE) {
$record['subparts'][$key] = array (
'uid' => $resArray->uid,
'page' => $resArray->page,
'thumbnail' => $resArray->thumbnail,
'metadata' => $metadata
);
}
}
}
}
// Save record for later usage.
$this->records[$element['u']] = $record;
} else {
if (TYPO3_DLOG) {
t3lib_div::devLog('[tx_dlf_list->getRecord([data])] No UID for list element to fetch full record', $this->extKey, SYSLOG_SEVERITY_WARNING, $element);
t3lib_div::devLog('[tx_dlf_list->getRecord([data])] No UID of list element to fetch full record', $this->extKey, SYSLOG_SEVERITY_NOTICE, $element);
}
// Return list element unchanged.
$record = $element;
}
@ -406,6 +555,8 @@ class tx_dlf_list implements ArrayAccess, Countable, Iterator, t3lib_Singleton {
$this->elements = array ();
$this->elementsRecords = array ();
$this->metadata = array ();
$this->count = 0;
@ -454,6 +605,49 @@ class tx_dlf_list implements ArrayAccess, Countable, Iterator, t3lib_Singleton {
}
/**
* Connects to Solr server.
*
* @access protected
*
* @return boolean TRUE on success or FALSE on failure
*/
protected function solrConnect() {
// Get Solr instance.
if (!$this->solr) {
// Connect to Solr server.
if ($this->solr = tx_dlf_solr::getInstance($this->metadata['options']['core'])) {
// Load index configuration.
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.tokenized AS tokenized,tx_dlf_metadata.indexed AS indexed',
'tx_dlf_metadata',
'tx_dlf_metadata.is_listed=1 AND tx_dlf_metadata.pid='.intval($this->metadata['options']['pid']).tx_dlf_helper::whereClause('tx_dlf_metadata'),
'',
'tx_dlf_metadata.sorting ASC',
''
);
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
$this->solrConfig[$resArray['index_name']] = $resArray['index_name'].'_'.($resArray['tokenized'] ? 't' : 'u').'s'.($resArray['indexed'] ? 'i' : 'u');
}
} else {
return FALSE;
}
}
return TRUE;
}
/**
* This sorts the current list by the given field
*
@ -473,9 +667,9 @@ class tx_dlf_list implements ArrayAccess, Countable, Iterator, t3lib_Singleton {
foreach ($this->elements as $num => $element) {
// Is this element sortable?
if (!empty($element['sorting'][$by])) {
if (!empty($element['s'][$by])) {
$newOrder[$element['sorting'][$by].str_pad($num, 6, '0', STR_PAD_LEFT)] = $element;
$newOrder[$element['s'][$by].str_pad($num, 6, '0', STR_PAD_LEFT)] = $element;
} else {

View File

@ -292,54 +292,32 @@ class tx_dlf_solr {
if ($this->numberOfHits > 0) {
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.tokenized AS tokenized,tx_dlf_metadata.indexed AS indexed,tx_dlf_metadata.is_listed AS is_listed,tx_dlf_metadata.is_sortable AS is_sortable',
'tx_dlf_metadata.index_name AS index_name',
'tx_dlf_metadata',
'(tx_dlf_metadata.is_listed=1 OR tx_dlf_metadata.is_sortable=1) AND tx_dlf_metadata.pid='.intval($this->cPid).tx_dlf_helper::whereClause('tx_dlf_metadata'),
'tx_dlf_metadata.is_sortable=1 AND tx_dlf_metadata.pid='.intval($this->cPid).tx_dlf_helper::whereClause('tx_dlf_metadata'),
'',
'',
'tx_dlf_metadata.sorting ASC',
''
);
$metadata = array ();
$sorting = array ();
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
if ($resArray['is_listed']) {
$metadata[$resArray['index_name']] = $resArray['index_name'].'_'.($resArray['tokenized'] ? 't' : 'u').'s'.($resArray['indexed'] ? 'i' : 'u');
}
if ($resArray['is_sortable']) {
$sorting[$resArray['index_name']] = $resArray['index_name'].'_sorting';
}
}
}
// Keep track of relevance.
$i = 0;
// Process results.
foreach ($results->response->docs as $doc) {
// Prepare document's metadata.
$docMeta = array ();
foreach ($metadata as $index_name => $solr_name) {
if (!empty($doc->$solr_name)) {
$docMeta[$index_name] = (is_array($doc->$solr_name) ? $doc->$solr_name : array ($doc->$solr_name));
}
}
// Split toplevel documents from subparts.
if ($doc->toplevel == 1) {
// Prepare document's metadata for sorting.
$docSorting = array ();
@ -357,27 +335,15 @@ class tx_dlf_solr {
// Add relevance to sorting values.
$docSorting['relevance'] = str_pad($i, 6, '0', STR_PAD_LEFT);
// Split toplevel documents from subparts.
if ($doc->toplevel == 1) {
$toplevel[$doc->uid] = array (
'uid' => $doc->uid,
'page' => $doc->page,
'thumbnail' => $doc->thumbnail,
'metadata' => $docMeta,
'sorting' => $docSorting,
'subparts' => (!empty($toplevel[$doc->uid]['subparts']) ? $toplevel[$doc->uid]['subparts'] : array ())
'u' => $doc->uid,
's' => $docSorting,
'p' => (!empty($toplevel[$doc->uid]['p']) ? $toplevel[$doc->uid]['p'] : array ())
);
} else {
$toplevel[$doc->uid]['subparts'][] = array (
'uid' => $doc->uid,
'page' => $doc->page,
'thumbnail' => $doc->thumbnail,
'metadata' => $docMeta,
'sorting' => $docSorting
);
$toplevel[$doc->uid]['p'][] = $doc->id;
if (!in_array($doc->uid, $checks)) {
@ -394,11 +360,11 @@ class tx_dlf_solr {
// Check if the toplevel documents have metadata.
foreach ($checks as $check) {
if (empty($toplevel[$check]['uid'])) {
if (empty($toplevel[$check]['u'])) {
// Get information for toplevel document.
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_documents.uid AS uid,tx_dlf_documents.thumbnail AS thumbnail,tx_dlf_documents.metadata AS metadata,tx_dlf_documents.metadata_sorting AS metadata_sorting',
'tx_dlf_documents.uid AS uid,tx_dlf_documents.metadata_sorting AS metadata_sorting',
'tx_dlf_documents',
'tx_dlf_documents.uid='.intval($check).tx_dlf_helper::whereClause('tx_dlf_documents'),
'',
@ -411,35 +377,6 @@ class tx_dlf_solr {
$resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
// Prepare document's metadata.
$metadata = unserialize($resArray['metadata']);
if (!empty($metadata['type'][0]) && t3lib_div::testInt($metadata['type'][0])) {
$metadata['type'][0] = tx_dlf_helper::getIndexName($metadata['type'][0], 'tx_dlf_structures', $this->cPid);
}
if (!empty($metadata['owner'][0]) && t3lib_div::testInt($metadata['owner'][0])) {
$metadata['owner'][0] = tx_dlf_helper::getIndexName($metadata['owner'][0], 'tx_dlf_libraries', $this->cPid);
}
if (!empty($metadata['collection']) && is_array($metadata['collection'])) {
foreach ($metadata['collection'] as $i => $collection) {
if (t3lib_div::testInt($collection)) {
$metadata['collection'][$i] = tx_dlf_helper::getIndexName($metadata['collection'][$i], 'tx_dlf_collections', $this->cPid);
}
}
}
// Prepare document's metadata for sorting.
$sorting = unserialize($resArray['metadata_sorting']);
@ -462,12 +399,9 @@ class tx_dlf_solr {
}
$toplevel[$check] = array (
'uid' => $resArray['uid'],
'page' => 1,
'thumbnail' => $resArray['thumbnail'],
'metadata' => $metadata,
'sorting' => $sorting,
'subparts' => $toplevel[$check]['subparts']
'u' => $resArray['uid'],
's' => $sorting,
'p' => $toplevel[$check]['p']
);
} else {
@ -497,6 +431,8 @@ class tx_dlf_solr {
'select' => $query,
'userid' => 0,
'params' => $this->params,
'core' => $this->core,
'pid' => $this->cPid,
'order' => 'relevance',
'order.asc' => TRUE,
)

View File

@ -303,7 +303,7 @@ class tx_dlf_modIndexing extends tx_dlf_module {
$this->list = t3lib_div::makeInstance('tx_dlf_list', $elements);
// Start index looping.
if ($this->list->count) {
if (count($this->list) > 0) {
$this->indexLoop();
@ -322,7 +322,7 @@ class tx_dlf_modIndexing extends tx_dlf_module {
$this->list = t3lib_div::makeInstance('tx_dlf_list');
// Continue index looping.
if ($this->list->count && isset($this->data['core'])) {
if (count($this->list) > 0 && isset($this->data['core'])) {
$this->indexLoop();

View File

@ -299,7 +299,7 @@ class tx_dlf_collection extends tx_dlf_plugin {
// Get all documents in collection.
$result = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
'tx_dlf_collections.index_name AS index_name,tx_dlf_collections.label AS collLabel,tx_dlf_collections.description AS collDesc,tx_dlf_collections.fe_cruser_id AS userid,tx_dlf_documents.uid AS uid,tx_dlf_documents.thumbnail AS thumbnail,tx_dlf_documents.metadata AS metadata,tx_dlf_documents.metadata_sorting AS metadata_sorting,tx_dlf_documents.volume_sorting AS volume_sorting,tx_dlf_documents.partof AS partof',
'tx_dlf_collections.index_name AS index_name,tx_dlf_collections.label AS collLabel,tx_dlf_collections.description AS collDesc,tx_dlf_collections.fe_cruser_id AS userid,tx_dlf_documents.uid AS uid,tx_dlf_documents.metadata_sorting AS metadata_sorting,tx_dlf_documents.volume_sorting AS volume_sorting,tx_dlf_documents.partof AS partof',
'tx_dlf_documents',
'tx_dlf_relations',
'tx_dlf_collections',
@ -328,6 +328,8 @@ class tx_dlf_collection extends tx_dlf_plugin {
'select' => $id,
'userid' => $resArray['userid'],
'params' => array ('fq' => array ('collection_faceting:"'.$resArray['index_name'].'"')),
'core' => '',
'pid' => $this->conf['pages'],
'order' => 'title',
'order.asc' => TRUE
)
@ -335,34 +337,8 @@ class tx_dlf_collection extends tx_dlf_plugin {
}
// Prepare document's metadata.
$metadata = unserialize($resArray['metadata']);
if (!empty($metadata['type'][0]) && t3lib_div::testInt($metadata['type'][0])) {
$metadata['type'][0] = tx_dlf_helper::getIndexName($metadata['type'][0], 'tx_dlf_structures', $this->conf['pages']);
}
if (!empty($metadata['owner'][0]) && t3lib_div::testInt($metadata['owner'][0])) {
$metadata['owner'][0] = tx_dlf_helper::getIndexName($metadata['owner'][0], 'tx_dlf_libraries', $this->conf['pages']);
}
if (!empty($metadata['collection']) && is_array($metadata['collection'])) {
foreach ($metadata['collection'] as $i => $collection) {
if (t3lib_div::testInt($collection)) {
$metadata['collection'][$i] = tx_dlf_helper::getIndexName($metadata['collection'][$i], 'tx_dlf_collections', $this->conf['pages']);
}
}
}
// Split toplevel documents from volumes.
if ($resArray['partof'] == 0) {
// Prepare document's metadata for sorting.
$sorting = unserialize($resArray['metadata_sorting']);
@ -385,27 +361,15 @@ class tx_dlf_collection extends tx_dlf_plugin {
}
// Split toplevel documents from volumes.
if ($resArray['partof'] == 0) {
$toplevel[$resArray['uid']] = array (
'uid' => $resArray['uid'],
'page' => 1,
'thumbnail' => $resArray['thumbnail'],
'metadata' => $metadata,
'sorting' => $sorting,
'subparts' => array ()
'u' => $resArray['uid'],
's' => $sorting,
'p' => array ()
);
} else {
$subparts[$resArray['partof']][$resArray['volume_sorting']] = array (
'uid' => $resArray['uid'],
'page' => 1,
'thumbnail' => $resArray['thumbnail'],
'metadata' => $metadata,
'sorting' => $sorting
);
$subparts[$resArray['partof']][$resArray['volume_sorting']] = $resArray['uid'];
}
@ -418,7 +382,7 @@ class tx_dlf_collection extends tx_dlf_plugin {
ksort($parts);
$toplevel[$partof]['subparts'] = array_values($parts);
$toplevel[$partof]['p'] = array_values($parts);
}

View File

@ -73,7 +73,7 @@ class tx_dlf_listview extends tx_dlf_plugin {
protected function getPagebrowser() {
// Get overall number of pages.
$maxPages = intval(ceil($this->list->count / $this->conf['limit']));
$maxPages = intval(ceil(count($this->list) / $this->conf['limit']));
// Return empty pagebrowser if there is just one page.
if ($maxPages < 2) {
@ -164,7 +164,7 @@ class tx_dlf_listview extends tx_dlf_plugin {
$imgAlt = '';
$metadata = $this->list->elements[$number]['metadata'];
$metadata = $this->list[$number]['metadata'];
foreach ($this->metadata as $index_name => $metaConf) {
@ -182,7 +182,7 @@ class tx_dlf_listview extends tx_dlf_plugin {
// Get title of parent document if needed.
if (empty($value) && $this->conf['getTitle']) {
$value = '['.tx_dlf_document::getTitle($this->list->elements[$number]['uid'], TRUE).']';
$value = '['.tx_dlf_document::getTitle($this->list[$number]['uid'], TRUE).']';
}
@ -195,7 +195,7 @@ class tx_dlf_listview extends tx_dlf_plugin {
$imgAlt = htmlspecialchars($value);
$value = $this->pi_linkTP(htmlspecialchars($value), array ($this->prefixId => array ('id' => $this->list->elements[$number]['uid'], 'page' => $this->list->elements[$number]['page'], 'pointer' => $this->piVars['pointer'])), TRUE, $this->conf['targetPid']);
$value = $this->pi_linkTP(htmlspecialchars($value), array ($this->prefixId => array ('id' => $this->list[$number]['uid'], 'page' => $this->list[$number]['page'], 'pointer' => $this->piVars['pointer'])), TRUE, $this->conf['targetPid']);
// Translate name of holding library.
} elseif ($index_name == 'owner' && !empty($value)) {
@ -241,13 +241,13 @@ class tx_dlf_listview extends tx_dlf_plugin {
}
// Add thumbnail.
if (!empty($this->list->elements[$number]['thumbnail'])) {
if (!empty($this->list[$number]['thumbnail'])) {
$markerArray['###THUMBNAIL###'] = '<img alt="'.$imgAlt.'" src="'.$this->list->elements[$number]['thumbnail'].'" />';
$markerArray['###THUMBNAIL###'] = '<img alt="'.$imgAlt.'" src="'.$this->list[$number]['thumbnail'].'" />';
}
if (!empty($this->list->elements[$number]['subparts'])) {
if (!empty($this->list[$number]['subparts'])) {
$subpart = $this->getSubEntries($number, $template);
@ -344,7 +344,7 @@ class tx_dlf_listview extends tx_dlf_plugin {
$content = '';
foreach ($this->list->elements[$number]['subparts'] as $subpart) {
foreach ($this->list[$number]['subparts'] as $subpart) {
$markerArray['###SUBMETADATA###'] = '';
@ -540,7 +540,7 @@ class tx_dlf_listview extends tx_dlf_plugin {
$subpartArray['subentry'] = $this->cObj->getSubpart($this->template, '###SUBENTRY###');
// Set some variable defaults.
if (!empty($this->piVars['pointer']) && (($this->piVars['pointer'] * $this->conf['limit']) + 1) <= $this->list->count) {
if (!empty($this->piVars['pointer']) && (($this->piVars['pointer'] * $this->conf['limit']) + 1) <= count($this->list)) {
$this->piVars['pointer'] = max(intval($this->piVars['pointer']), 0);
@ -555,7 +555,7 @@ class tx_dlf_listview extends tx_dlf_plugin {
for ($i = $this->piVars['pointer'] * $this->conf['limit'], $j = ($this->piVars['pointer'] + 1) * $this->conf['limit']; $i < $j; $i++) {
if (empty($this->list->elements[$i])) {
if (empty($this->list[$i])) {
break;
@ -573,7 +573,7 @@ class tx_dlf_listview extends tx_dlf_plugin {
if ($i) {
$markerArray['###COUNT###'] = htmlspecialchars(sprintf($this->pi_getLL('count'), ($this->piVars['pointer'] * $this->conf['limit']) + 1, $i, $this->list->count));
$markerArray['###COUNT###'] = htmlspecialchars(sprintf($this->pi_getLL('count'), ($this->piVars['pointer'] * $this->conf['limit']) + 1, $i, count($this->list)));
} else {

View File

@ -52,7 +52,7 @@ class tx_dlf_navigation extends tx_dlf_plugin {
// Load the list.
$list = t3lib_div::makeInstance('tx_dlf_list');
if ($list->count > 0) {
if (count($list) > 0) {
// Build typolink configuration array.
$conf = array (

View File

@ -1145,7 +1145,7 @@ class tx_dlf_oai extends tx_dlf_plugin {
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
// Save only UIDs for resumption token.
$results[] = array ('uid' => $resArray['uid']);
$results[] = $resArray['uid'];
}
@ -1163,7 +1163,7 @@ class tx_dlf_oai extends tx_dlf_plugin {
for ($i = 0, $j = intval($this->conf['limit']); $i < $j; $i++) {
$todo[] = $results[$i]['uid'];
$todo[] = $results[$i];
if (empty($results[$i + 1])) {
@ -1521,7 +1521,7 @@ class tx_dlf_oai extends tx_dlf_plugin {
while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
// Save only UIDs for resumption token.
$results[] = array ('uid' => $resArray['uid']);
$results[] = $resArray['uid'];
}
@ -1533,7 +1533,7 @@ class tx_dlf_oai extends tx_dlf_plugin {
for ($i = 0, $j = intval($this->conf['limit']); $i < $j; $i++) {
$todo[] = $results[$i]['uid'];
$todo[] = $results[$i];
if (empty($results[$i + 1])) {