function fieldable_panels_panes_update_7115 in Fieldable Panels Panes (FPP) 7
Update all Panelizer displays to point non-reusable FPPs to the vuuid.
(instead of the uuid)
File
- ./
fieldable_panels_panes.install, line 728 - Fieldable Panels Panes install file.
Code
function fieldable_panels_panes_update_7115(&$sandbox) {
if (!module_exists('panelizer')) {
return t('Panelizer is not installed, so nothing to do.');
}
// This won't as-is work for many sites because the 'fpp_revision_locking'
// variable won't be defined before it's checked for. The simplest approach
// is to manually rerun the updates.
//
// @code
// /**
// * Enable the FPP revision locking feature.
// */
// function MYMODULE_update_7100() {
// variable_set('fpp_revision_locking', 'lock');
// }
//
// /**
// * Rerun Fieldable Panels Panes update 7115.
// */
// function MYMODULE_update_7101(&$sandbox) {
// return fieldable_panels_panes_update_7115($sandbox);
// }
// @endcode
//
// A more correct approach is to use hook_update_dependencies to ensure that
// the updates happen in the correct order. This may not work because if the
// hook implementation is newly added to the module it won't be recognized
// until the caches are cleared, which may not happen until after the updates
// are ran, thus the updates not running in the correct order.
//
// @code
// /**
// * Implements hook_update_dependencies().
// */
// function MYMODULE_update_dependencies() {
// // Make sure that update 7100 below runs *after* Fieldable Panels Pane
// // update 7111 and *before* Fieldable Panels Pane update 7112, that way
// // the FPP 'lock' option will be enabled when the Panelizer updates are
// // started.
// $dependencies['MYMODULE'][7100] = array(
// 'fieldable_panels_panes' => 7111,
// );
// $dependencies['fieldable_panels_panes'][7115] = array(
// 'MYMODULE' => 7100,
// );
// return $dependencies;
// }
//
// /**
// * Enable the FPP revision locking feature.
// */
// function MYMODULE_update_7100() {
// variable_set('fpp_revision_locking', 'lock');
// }
// @endcode
//
// An alternative solution would be to rerun the updates.
if (variable_get('fpp_revision_locking', 'lock') != 'lock') {
return t('Pane locking is not enabled, so nothing to do.');
}
// Update all Panelizer displays.
// The first time through, work out how many records need to be updated.
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
// Total records that must be processed.
$sandbox['max'] = db_query("SELECT DISTINCT fpp.uuid as uuid, fppr.vuuid as vuuid\n FROM {fieldable_panels_panes} fpp\n INNER JOIN {fieldable_panels_panes_revision} fppr\n ON fpp.vid = fppr.vid\n INNER JOIN {panels_pane} pp\n ON fpp.uuid = SUBSTRING(pp.subtype FROM (POSITION(':' IN pp.subtype) + 1))\n INNER JOIN {panelizer_entity} pe\n ON pe.did = pp.did\n WHERE (pp.subtype LIKE 'uuid:%')\n AND fpp.reusable != 1\n ORDER BY fpp.uuid")
->rowCount();
// If there's nothing to do, bail early.
if (empty($sandbox['max'])) {
return t('No panels needed to be updated.');
}
}
// Do the updates in small batches.
$limit = 10;
// Get a list of all UUIDs for Panelizer displays.
$results = db_query_range("SELECT DISTINCT fpp.uuid as uuid, fppr.vuuid as vuuid\n FROM {fieldable_panels_panes} fpp\n INNER JOIN {fieldable_panels_panes_revision} fppr\n ON fpp.vid = fppr.vid\n INNER JOIN {panels_pane} pp\n ON fpp.uuid = SUBSTRING(pp.subtype FROM (POSITION(':' IN pp.subtype) + 1))\n INNER JOIN {panelizer_entity} pe\n ON pe.did = pp.did\n WHERE (pp.subtype LIKE 'uuid:%')\n AND fpp.reusable != 1\n ORDER BY fpp.uuid", 0, $limit);
// Loop through the FPPs.
foreach ($results as $record) {
// Update the 'uuid:' records to use 'vuuid:'; don't bother checking if the
// record exists first because there's no down side to running this query
// immediately.
$query = db_update('panels_pane')
->fields(array(
'subtype' => 'vuuid:' . $record->vuuid,
))
->condition('subtype', 'uuid:' . $record->uuid)
->execute();
// Increment the progress counter.
$sandbox['progress']++;
}
// Done yet?
$sandbox['#finished'] = empty($sandbox['max']) ? TRUE : $sandbox['progress'] / $sandbox['max'];
if ($sandbox['#finished'] === TRUE) {
return t('Updated @count record(s) to use the new locking system.', array(
'@count' => $sandbox['max'],
));
}
}