Projet

Général

Profil

Paste
Télécharger (3,9 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / css_injector / css_injector.install @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the css_injector module.
6
 *
7
 */
8

    
9
/**
10
 * Implements hook_install().
11
 */
12
function css_injector_install() {
13
}
14

    
15
/**
16
 * Implements hook_schema().
17
 */
18
function css_injector_schema() {
19
  $schema['css_injector_rule'] = array(
20
    'fields' => array(
21
      'crid' => array(
22
        'description' => 'The primary identifier for the CSS injection rule',
23
        'type' => 'serial',
24
        'unsigned' => TRUE,
25
        'not null' => TRUE),
26
      'title' => array(
27
        'description' => 'The descriptive title of the CSS injection rule',
28
        'type' => 'varchar',
29
        'length' => 255,
30
        'not null' => TRUE),
31
      'rule_type' => array(
32
        'description' => 'The type of rule to use when determining if the CSS should be injected',
33
        'type' => 'int',
34
        'unsigned' => TRUE,
35
        'not null' => TRUE,
36
        'default' => 0),
37
      'rule_conditions' => array(
38
        'description' => 'The data to evaluate when determining if the CSS should be injected',
39
        'type' => 'text',
40
        'not null' => TRUE),
41
      'rule_themes' => array(
42
        'description' => 'Themes that CSS rule will be applied to',
43
        'type' => 'text',
44
        'not null' => TRUE),
45
      'media' => array(
46
        'description' => 'The media type of the CSS file (screen, print, etc.)',
47
        'type' => 'varchar',
48
        'length' => 255,
49
        'not null' => TRUE),
50
      'preprocess' => array(
51
        'description' => 'Whether the CSS file should be included by the CSS preprocessor',
52
        'type' => 'int',
53
        'unsigned' => TRUE,
54
        'not null' => TRUE,
55
        'default' => 0),
56
      'enabled' => array(
57
        'description' => 'Whether the rules should be enabled',
58
        'type' => 'int',
59
        'unsigned' => TRUE,
60
        'not null' => TRUE,
61
        'default' => 1),
62
    ),
63
    'primary key' => array('crid'),
64
  );
65
  return $schema;
66
}
67

    
68
/**
69
 * Adds enabled rule and themes list.
70
 */
71
function css_injector_update_7002() {
72
  $enabled = array(
73
    'description' => 'Whether the rules should be enabled',
74
    'type' => 'int',
75
    'unsigned' => TRUE,
76
    'not null' => TRUE,
77
    'default' => 1,
78
  );
79
  $themes = array(
80
    'description' => 'Themes that CSS rule will be applied to',
81
    'type' => 'text',
82
  );
83
  if (!db_field_exists('css_injector_rule', 'enabled')) {
84
    db_add_field( 'css_injector_rule', 'enabled', $enabled);
85
  }
86
  if (!db_field_exists('css_injector_rule', 'rule_themes')) {
87
    db_add_field( 'css_injector_rule', 'rule_themes', $themes);
88
  } else {
89
    db_change_field('css_injector_rule', 'rule_themes', 'rule_themes', array('type' => 'text', 'not null' => FALSE));
90
  }
91
}
92

    
93
/**
94
 * Implements hook_uninstall().
95
 */
96
function css_injector_uninstall() {
97
  cache_clear_all('css_injector:*', 'cache', TRUE);
98
  $rules = db_query("SELECT * FROM {css_injector_rule}", array(), array('fetch' => PDO::FETCH_ASSOC))->fetchAllAssoc('crid');
99
  module_load_include('module', 'css_injector');
100
  foreach($rules as $crid => $rule) {
101
    file_unmanaged_delete(_css_injector_rule_uri($crid));
102
  }
103
  db_drop_table('css_injector_rule');
104
}
105

    
106
/**
107
 * Implements hook_requirements().
108
 * We'll use this to prevent installation of the module if the file directory
109
 * is not available and writable.
110
 */
111
function css_injector_requirements($phase) {
112
  $status = REQUIREMENT_OK;
113
  $dir = 'public://css_injector';
114
  if (!file_prepare_directory($dir, FILE_MODIFY_PERMISSIONS)) {
115
    if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
116
      $status = REQUIREMENT_ERROR;
117
    }
118
  }
119
  $requirements = array(
120
    'css_injector' => array(
121
      'title' => t('CSS Injector directory writable'),
122
      'description' => $status == REQUIREMENT_OK ? t('CSS Injector Directory %dir is writable', array('%dir' => $dir)) : t('Directory %dir is not writable', array('%dir' => $dir)),
123
      'severity' => $status,
124
      'value' => $status == REQUIREMENT_OK ? t('Writable') : t('Not writable'),
125
    ),
126
  );
127
  return $requirements;
128
}