Projet

Général

Profil

Paste
Télécharger (5,08 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panels / panels_mini / panels_mini.install @ 136a805a

1
<?php
2

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

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

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

    
94
  return $schema;
95
}
96

    
97
/**
98
 * Implementation of hook_uninstall().
99
 */
100
function panels_mini_uninstall() {
101
  $panels_exists = db_table_exists('panels_display');
102

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

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

    
117
  if (db_table_exists('block') && $deltas) {
118
    // Delete all configured blocks.
119
    db_delete('block')
120
      ->condition('module', 'panels_mini')
121
      ->condition('delta', $deltas)
122
      ->execute();
123
  }
124
}
125

    
126
/**
127
 * Implements hook_update_dependencies().
128
 */
129
function panels_mini_update_dependencies() {
130
  // Update 7301 requires panels storage support
131
  $dependencies['panels_mini'][7301] = array(
132
    'panels' => 7305,
133
  );
134

    
135
  return $dependencies;
136
}
137

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

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

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

    
161
  foreach ($result as $row) {
162
    db_update('panels_display')
163
      ->fields(array(
164
        'storage_type' => 'panels_mini',
165
        'storage_id' => $row->name,
166
      ))
167
      ->condition('did', $row->did)
168
      ->execute();
169

    
170
    // Update our progress information.
171
    $sandbox['progress']++;
172
    $sandbox['current_did'] = $row->did;
173
  }
174

    
175
  // Set the "finished" status, to tell batch engine whether this function
176
  // needs to run again.
177
  $sandbox['#finished'] = ($sandbox['progress'] >= $sandbox['max']) ? TRUE : ($sandbox['progress'] / $sandbox['max']);
178

    
179
  if ($sandbox['#finished']) {
180
    return t('Added the storage type for panels_mini to relevant panels displays');
181
  }
182
}