panels_mini.install 5.08 KB
Newer Older
1 2
<?php

3 4 5 6 7 8 9 10
/**
 * Implementation of hook_schema().
 */
function panels_mini_schema() {
  // This should always point to our 'current' schema. This makes it relatively easy
  // to keep a record of schema as we make changes to it.
  return panels_mini_schema_1();
}
11 12

/**
13
 * Schema version 1 for Panels in D6.
14
 */
15 16 17 18
function panels_mini_schema_1() {
  $schema = array();

  $schema['panels_mini'] = array(
19 20
    'export' => array(
      'identifier' => 'mini',
21 22 23 24
      'load callback' => 'panels_mini_load',
      'load all callback' => 'panels_mini_load_all',
      'save callback' => 'panels_mini_save',
      'delete callback' => 'panels_mini_delete',
25 26 27 28 29 30 31 32
      'export callback' => 'panels_mini_export',
      'api' => array(
        'owner' => 'panels_mini',
        'api' => 'panels_default',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
33 34 35 36
    'fields' => array(
      'pid' => array(
        'type' => 'serial',
        'not null' => TRUE,
37
        'no export' => TRUE,
38
        'description' => 'The primary key for uniqueness.',
39 40 41 42
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => '255',
43
        'description' => 'The unique name of the mini panel.',
44 45 46 47
      ),
      'category' => array(
        'type' => 'varchar',
        'length' => '64',
48
        'description' => 'The category this mini panel appears in on the add content pane.',
49 50 51
      ),
      'did' => array(
        'type' => 'int',
52
        'no export' => TRUE,
53
        'description' => 'The display ID of the panel.',
54
      ),
55
      'admin_title' => array(
56 57
        'type' => 'varchar',
        'length' => '128',
58 59 60 61 62 63 64
        'description' => 'The administrative title of the mini panel.',
      ),
      'admin_description' => array(
        'type' => 'text',
        'size' => 'big',
        'description' => 'Administrative title of this mini panel.',
        'object default' => '',
65 66 67 68
      ),
      'requiredcontexts' => array(
        'type' => 'text',
        'size' => 'big',
69 70
        'serialize' => TRUE,
        'object default' => array(),
71
        'description' => 'An array of required contexts.',
72 73 74 75
      ),
      'contexts' => array(
        'type' => 'text',
        'size' => 'big',
76 77
        'serialize' => TRUE,
        'object default' => array(),
78
        'description' => 'An array of contexts embedded into the panel.',
79 80 81 82
      ),
      'relationships' => array(
        'type' => 'text',
        'size' => 'big',
83 84
        'serialize' => TRUE,
        'object default' => array(),
85
        'description' => 'An array of relationships embedded into the panel.',
86 87 88 89 90 91 92 93 94 95
      ),
    ),
    'primary key' => array('pid'),
    'unique keys' => array(
      'name' => array('name'),
    ),
  );

  return $schema;
}
96 97 98 99 100 101

/**
 * Implementation of hook_uninstall().
 */
function panels_mini_uninstall() {
  $panels_exists = db_table_exists('panels_display');
102 103 104 105

  $result = db_query("SELECT * FROM {panels_mini}");
  $deltas = array();
  foreach ($result as $panel_mini) {
106 107 108 109 110 111 112 113
    // Delete all associated displays.
    if (!function_exists('panels_delete_display')) {
      require_once drupal_get_path('module', 'panels') .'/panels.module';
    }
    if ($panels_exists) {
      panels_delete_display($panel_mini->did);
    }

114 115 116
    $deltas[] = $panel_mini->pid;
  }

117
  if (db_table_exists('block') && $deltas) {
118
    // Delete all configured blocks.
119
    db_delete('block')
120 121 122
      ->condition('module', 'panels_mini')
      ->condition('delta', $deltas)
      ->execute();
123 124
  }
}
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

/**
 * Implements hook_update_dependencies().
 */
function panels_mini_update_dependencies() {
  // Update 7301 requires panels storage support
  $dependencies['panels_mini'][7301] = array(
    'panels' => 7305,
  );

  return $dependencies;
}

/**
 * Set the storage type and id on existing mini panels.
 */
function panels_mini_update_7301() {
  if (!isset($sandbox['progress'])) {
     // Initialize batch update information.
     $sandbox['progress'] = (float)0;
     $sandbox['current_did'] = -1;
     $sandbox['max'] = db_query("SELECT COUNT(pd.did)
         FROM {panels_display} pd
           JOIN {panels_mini} pm ON pm.did = pd.did
         WHERE pd.storage_type = ''")->fetchField();
   }

  // Set a limit of how many rows to process per batch.
  $limit = 1000;

  // Run the query
  $result = db_query_range("SELECT pd.did, pm.name
      FROM {panels_display} pd
        JOIN {panels_mini} pm ON pm.did = pd.did
      WHERE pd.storage_type = '' AND pd.did > :current_did", 0, $limit, array(':current_did' => $sandbox['current_did']));

  foreach ($result as $row) {
    db_update('panels_display')
      ->fields(array(
        'storage_type' => 'panels_mini',
        'storage_id' => $row->name,
      ))
      ->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 panels_mini to relevant panels displays');
  }
}