Project

General

Profile

« Previous | Next » 

Revision 995

Added by aldus over 15 years ago

update upgrade-script to avoid droping droplet-tables if the modul still exists. Add an upgrade-script to the droplets.

View differences:

upgrade-script.php
233 233
 *  - install droplets
234 234
 */
235 235
echo "<br />Install droplets<br />";
236
$table = TABLE_PREFIX .'mod_droplets';
237
$database->query("DROP TABLE IF EXISTS `$table`");
238 236

  
239
$database->query("CREATE TABLE `$table` (
240
	`id` INT NOT NULL auto_increment,
241
	`name` VARCHAR(32) NOT NULL,
242
	`code` LONGTEXT NOT NULL ,
243
	`description` TEXT NOT NULL,
244
	`modified_when` INT NOT NULL default '0',
245
	`modified_by` INT NOT NULL default '0',
246
	`active` INT NOT NULL default '0',
247
	`admin_edit` INT NOT NULL default '0',
248
	`admin_view` INT NOT NULL default '0',
249
	`show_wysiwyg` INT NOT NULL default '0',
250
	`comments` TEXT NOT NULL,
251
	PRIMARY KEY ( `id` )
252
	)"
253
);
237
$result = mysql_list_tables( DB_NAME );
238
$all_tables = array();
239
for($i=0; $i < mysql_num_rows($result); $i++) $all_tables[] = mysql_table_name($result, $i);
254 240

  
255
//add all droplets from the droplet subdirectory
256
$folder=opendir(WB_PATH.'/modules/droplets/example/.'); 
257
$names = array();
258
while ($file = readdir($folder)) {
259
	$ext=strtolower(substr($file,-4));
260
	if ($ext==".php"){
261
		if ($file<>"index.php" ) {
262
			$names[count($names)] = $file; 
263
		}
264
	}
265
}
266
closedir($folder);
241
 $file_name = (!in_array ( TABLE_PREFIX."mod_droplets", $all_tables)) ? "install.php" : "upgrade.php";
242
 require_once (WB_PATH."/modules/droplets/".$file_name);
267 243

  
268
foreach ($names as $dropfile) {
269
	$droplet = addslashes(getDropletCodeFromFile($dropfile));
270
	if ($droplet != "") {
271
		$description = "Example Droplet";
272
		$comments = "Example Droplet";
273
		$cArray = explode("\n",$droplet);
274
		if (substr($cArray[0],0,3) == "//:") {
275
			$description = trim(substr($cArray[0],3));
276
			array_shift ( $cArray );
277
		}
278
		if (substr($cArray[0],0,3) == "//:") {
279
			$comments = trim(substr($cArray[0],3));
280
			array_shift ( $cArray );
281
		}
282
		$droplet = implode ( "\n", $cArray );
283
		$name = substr($dropfile,0,-4);
284
		$modified_when = mktime();
285
		$modified_by = method_exists($admin, 'get_user_id') ? $admin->get_user_id() : 1;
286
		echo ($database->query("INSERT INTO `$table`  
287
			(name, code, description, comments, active, modified_when, modified_by) 
288
			VALUES 
289
			('$name', '$droplet', '$description', '$comments', '1', '$modified_when', '$modified_by')"))? "$name: $OK<br />" : "$name: $FAIL<br />";
290
	}  
291
}
292

  
293

  
294
function getDropletCodeFromFile ( $dropletfile ) {
295
	$data = "";
296
	$filename = WB_PATH."/modules/droplets/example/".$dropletfile;
297
	if (file_exists($filename)) {
298
		$filehandle = fopen ($filename, "r");
299
		$data = fread ($filehandle, filesize ($filename));
300
		fclose($filehandle);
301
		// unlink($filename); doesnt work in unix
302
	}	
303
	return $data;
304
}
305

  
306 244
/**********************************************************
307 245
 *  - Reload all addons
308 246
 */

Also available in: Unified diff