diff --git a/fieldable_panels_panes.install b/fieldable_panels_panes.install index dad5c15..ff7d18c 100644 --- a/fieldable_panels_panes.install +++ b/fieldable_panels_panes.install @@ -381,7 +381,7 @@ function fieldable_panels_panes_update_7108() { // Store possible existing bundles provided by other modules. $bundles = array(); $entity_info = entity_get_info('fieldable_panels_pane'); - + // No bundles defined. This could happen if the module was updated and cache // cleared before update was run as entity info's cache will no longer // contain the old default. @@ -393,7 +393,7 @@ function fieldable_panels_panes_update_7108() { ), ); } - + foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) { $bundles[] = $bundle_info['label']; @@ -441,7 +441,7 @@ function fieldable_panels_panes_update_7111() { * Update all Panelizer displays to point non-reusable FPPs to the vid instead * of the fpid. */ -function fieldable_panels_panes_update_7112() { +function fieldable_panels_panes_update_7112(&$sandbox) { if (!module_exists('panelizer')) { return t('Panelizer is not installed, so nothing to do.'); } @@ -450,7 +450,52 @@ function fieldable_panels_panes_update_7112() { return t('Pane locking is not enabled, so nothing to do.'); } - // @todo Update all Panelizer displays. + // Update all Panelizer displays. + if (!isset($sandbox['progress'])) { + $sandbox['progress'] = 0; + $sandbox['limit'] = 1; + } + + // Get a list of all FPIDs for Panelizer displays. + $results = db_query("SELECT DISTINCT fpp.fpid as fpid, fpp.vid as vid + FROM {fieldable_panels_panes} fpp + INNER JOIN {panels_pane} pp + ON fpp.fpid = SUBSTRING_INDEX(pp.subtype, ':', -1) + INNER JOIN {panelizer_entity} pe + ON pe.did = pp.did + WHERE (pp.subtype LIKE 'fpid:%' OR pp.subtype LIKE 'current:%') + AND fpp.reusable != 1 + ORDER BY fpp.fpid"); + + // If there are no records, there's nothing to do. + if ($results->rowCount() == 0) { + return t('No records need fixing.'); + } + + // Total records that must be processed. + $sandbox['max'] = $results->rowCount(); + + // Loop through the FPPs. + foreach ($results as $record) { + $fstr = 'fpid:' . $record->fpid; + $vstr = 'vid:' . $record->vid; + // Check to see if there is a matching panel pane. + $sql = db_query('SELECT pid FROM {panels_pane} WHERE subtype = :var', array(':var' => $fstr))->fetchCol(); + + if (!empty($sql)) { + // If there is a matching panel pane, update the fpids to vids. + $query = db_update('panels_pane') + ->fields(array('subtype' => $vstr)) + ->condition('subtype', $fstr) + ->execute(); + } + // Increment $sandbox + $sandbox['progress']++; + } + + $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']); + + return t('Fixed @count record(s) (out of @total) that were using the same display.', array('@count' => $sandbox['progress'], '@total' => $sandbox['max'])); } /**