-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnameday.install
104 lines (94 loc) · 2.59 KB
/
nameday.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* @file
* Install, update and uninstall functions for the nameday module.
*/
/**
* Implements hook_schema().
*/
function nameday_schema() {
$schema['nameday'] = array(
'description' => 'Namedays',
'fields' => array(
'ndid' => array(
'description' => 'The primary identifier for a name day.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'month' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'day' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'language' => array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE
),
'name' => array(
'description' => 'The name in the original language',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE
),
'holiday' => array(
'description' => 'The holiday name in the original language',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE
),
),
'primary key' => array('ndid'),
);
return $schema;
}
/**
* Implements hook_install().
*/
function nameday_install() {
//sets the defaults
variable_set('nameday_show_date', TRUE);
variable_set('nameday_show_holiday', TRUE);
variable_set('nameday_date_format', 'small');
variable_set('nameday_date_format_custom', '');
$dir = drupal_get_path("module", "nameday") . "/data/";
$files = file_scan_directory($dir, '/.*namedays$/');
foreach ($files as $curr) {
$lang = $curr->name;
$langfile = file($curr->uri);
foreach ($langfile as $row) {
$currentrow = explode(";", $row);
if (count($currentrow) == 3) {
$currentrow[3] = "";
}
try {
$fields = array(
'month' => $currentrow[0],
'day' => $currentrow[1],
'language' => $lang,
'name' => $currentrow[2],
'holiday' => $currentrow[3]
);
$return_value = db_insert('nameday')->fields($fields)->execute();
} catch (Exception $e) {
drupal_set_message($e->getMessage());
}
//db_query("INSERT INTO {nameday} (month, day, language, name, holiday) VALUES (%d, %d, '%s', '%s', '%s')", $currentrow[0], $currentrow[1], $lang, $currentrow[2], $currentrow[3]);
}
}
}
/**
* Implements hook_uninstall().
*/
function nameday_uninstall() {
variable_del('nameday_show_date');
variable_del('nameday_show_holiday');
variable_del('nameday_date_format');
variable_del('nameday_date_format_custom');
}