function panelizer_update_7303 in Panelizer 7.3
Set the storage type and ID on existing {panelizer_entity} records. This may take some time to complete.
File
- ./
panelizer.install, line 1310 - Install, update and uninstall functions for the panelizer module.
Code
function panelizer_update_7303(&$sandbox) {
if (!isset($sandbox['progress'])) {
// Initialize batch update information.
$sandbox['progress'] = (double) 0;
$sandbox['current_did'] = -1;
$sandbox['max'] = db_query("SELECT COUNT(pd.did)\n FROM {panels_display} pd\n JOIN {panelizer_entity} p ON p.did = pd.did\n WHERE pd.storage_type = ''")
->fetchField();
if (empty($sandbox['max'])) {
return t('Nothing to be fixed in Panelizer update 7303.');
}
}
// Set a limit of how many rows to process per batch.
$limit = 100;
// Look for records to be updated.
$result = db_query_range("SELECT pd.did, p.entity_type, p.entity_id, p.view_mode\n FROM {panels_display} pd\n JOIN {panelizer_entity} p ON p.did = pd.did\n WHERE pd.storage_type = '' AND pd.did > :current_did\n ORDER BY pd.did ASC", 0, $limit, array(
':current_did' => $sandbox['current_did'],
));
// No results means that it's finished.
if (empty($result)) {
$sandbox['progress'] = $sandbox['max'];
}
else {
foreach ($result as $row) {
db_update('panels_display')
->fields(array(
'storage_type' => 'panelizer_entity',
'storage_id' => implode(':', array(
$row->entity_type,
$row->entity_id,
$row->view_mode,
)),
))
->condition('did', $row->did)
->execute();
// Update our progress information.
$sandbox['progress']++;
$sandbox['current_did'] = $row->did;
}
}
// Set the "finished" status, to tell batch engine whether this function
// needs to run again.
$sandbox['#finished'] = $sandbox['progress'] >= $sandbox['max'] ? TRUE : $sandbox['progress'] / $sandbox['max'];
if ($sandbox['#finished']) {
return t('Added the storage type for panelizer_entities to relevant panels displays');
}
}