/[drupal]/contributions/modules/slideshow/slideshow.install
ViewVC logotype

Contents of /contributions/modules/slideshow/slideshow.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Mon Jun 25 18:22:57 2007 UTC (2 years, 5 months ago) by timcn
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5--2
Changes since 1.4: +8 -6 lines
File MIME type: text/x-php
#135350 by Shiny: Add PostgreSQL support
1 <?php
2 // $Id: slideshow.install,v 1.4 2006/12/25 16:41:24 timcn Exp $
3
4 function slideshow_install() {
5 db_query("UPDATE {system} SET weight = 1 WHERE name = 'slideshow'");
6
7 // Insert a slideshow node type.
8 $type = array(
9 'type' => 'slideshow',
10 'name' => t('Slideshow'),
11 'module' => 'node',
12 'description' => t('Slideshows are a series of image nodes that are shown after each other. In modern browsers, the images are changed without reloading the entire page.'),
13 'custom' => TRUE,
14 'modified' => TRUE,
15 'locked' => FALSE,
16 );
17
18 $type = (object) _node_type_set_defaults($type);
19 node_type_save($type);
20
21 cache_clear_all();
22 system_modules();
23 menu_rebuild();
24 node_types_rebuild();
25
26 variable_set('slideshow_slideshow', TRUE);
27
28
29 // Create the table
30 switch ($GLOBALS['db_type']) {
31 case 'mysqli':
32 case 'mysql':
33 db_query("CREATE TABLE {slideshow} (
34 nid int NOT NULL default '0',
35 vid int unsigned NOT NULL DEFAULT '0',
36 location tinyint NOT NULL,
37 align tinyint NOT NULL,
38 dimensions varchar(20) NOT NULL,
39 PRIMARY KEY (nid, vid)
40 ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
41 break;
42 case 'pgsql':
43 db_query("CREATE TABLE {slideshow} (
44 nid integer NOT NULL default '0',
45 vid integer NOT NULL DEFAULT 0,
46 location INTEGER NOT NULL,
47 align INTEGER NOT NULL,
48 dimensions varchar(20) NULL,
49 PRIMARY KEY (nid, vid)
50 )");
51 }
52 }
53
54 function slideshow_update_1() {
55 return array(
56 update_sql("UPDATE {system} SET weight = 1 WHERE name = 'slideshow'")
57 );
58 }
59
60
61 // Update from 1.3 to 2.0
62 function slideshow_update_2() {
63 $ret = array();
64
65 // Insert a slideshow node type for backwards compatibility.
66 $type = array(
67 'type' => 'slideshow',
68 'name' => t('Slideshow'),
69 'module' => 'node',
70 'description' => t('Slideshows are a series of image nodes that are shown after each other. In modern browsers, the images are changed without reloading the entire page.'),
71 'custom' => TRUE,
72 'modified' => TRUE,
73 'locked' => FALSE,
74 );
75
76 // Migrate the variable
77 variable_set('slideshow_default_dimensions', variable_get('slideshow_size', '640x480'));
78 variable_del('slideshow_size');
79 variable_set('slideshow_slideshow', TRUE);
80
81 $type = (object) _node_type_set_defaults($type);
82 node_type_save($type);
83
84 cache_clear_all();
85 system_modules();
86 menu_rebuild();
87 node_types_rebuild();
88
89 $ret[] = array('success' => TRUE, 'query' => t('Added generic node type "slideshow".'));
90
91 // Create the table
92 switch ($GLOBALS['db_type']) {
93 case 'mysqli':
94 case 'mysql':
95 $ret[] = update_sql("CREATE TABLE {slideshow} (
96 nid int NOT NULL default '0',
97 vid int unsigned NOT NULL DEFAULT '0',
98 location tinyint NOT NULL,
99 align tinyint NOT NULL,
100 dimensions varchar(20) NOT NULL,
101 PRIMARY KEY (nid, vid)
102 ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
103 break;
104 case 'pgsql':
105 /*$ret[] = update_sql("CREATE TABLE {slideshow} (
106 nid int NOT NULL default '0',
107 dimensions varchar(20) NULL,
108 PRIMARY KEY (nid)
109 )");*/
110 // PostgreSQL support missing
111 }
112
113 // Now, delete old images
114 include_once drupal_get_path('module', 'slideshow') .'/slideshow.module';
115
116 $nodes = db_query("SELECT nid FROM {node} WHERE type = 'slideshow'");
117 while ($node = db_fetch_object($nodes)) {
118 // Load file attachments and delete old images
119 $result = db_query('SELECT filename FROM {files} WHERE nid = %d', $node->nid);
120 while ($file = db_fetch_object($result)) {
121 $info = pathinfo($file->filename);
122 $extension = $info['extension'];
123 $path = file_directory_path() .'/'. basename($file->filename, $extension) . variable_get('slideshow_default_dimensions', '640x480') .'.'. $extension;
124
125 file_delete($path);
126 }
127
128 // Load the actual node and create new files
129 $node = node_load($node->nid);
130 slideshow_update_images($node);
131
132 $ret[] = array('success' => TRUE, 'query' =>t('Updated post %title.', array('%title' => $node->title)));
133 }
134
135 return $ret;
136 }

  ViewVC Help
Powered by ViewVC 1.1.2