You are here

function fillpdf_update_7106 in FillPDF 7

Convert old JSON file contexts to the link-based format.

File

./fillpdf.install, line 327
Install.

Code

function fillpdf_update_7106() {
  $fcs = db_query("SELECT fcid, fid FROM {fillpdf_file_context}");
  foreach ($fcs as $fc) {
    $context = _fillpdf_old_file_context_load($fc->fcid);
    if ($context) {

      // We didn't store sample info in the past, but we know it's a sample if
      // all four array keys are empty.
      $sample = FALSE;
      if (empty($context['nodes']) && empty($context['webforms']) && empty($context['uc_orders']) && empty($context['uc_order_products'])) {
        $sample = TRUE;
      }
      $as_link = fillpdf_context_to_link($fc->fid, $context, $sample);

      // Update it to the link format in the database.
      db_update('fillpdf_file_context')
        ->fields(array(
        'context' => $as_link,
      ))
        ->condition('fcid', $fc->fcid)
        ->execute();
    }
  }
  drupal_set_message(t('Private file metadata migrated to the new format.'));
}