Project

General

Profile

« Previous | Next » 

Revision 580

Added by thorn almost 17 years ago

upgrade-script.php: added code to upgrade menu_links

View differences:

upgrade-script.php
204 204
/**********************************************************
205 205
 *  - core-module menu_link
206 206
 */
207
echo "<br /><u>Convert menu_links</u><br />";
207 208
// create table
208 209
$table = TABLE_PREFIX ."mod_menu_link";
209 210
$database->query("DROP TABLE IF EXISTS `$table`");
......
220 221
$pages = array();
221 222
$table_p = TABLE_PREFIX.'pages';
222 223
$table_s = TABLE_PREFIX.'sections';
223
$query_page = $database->query("SELECT p.* FROM $table_p AS p, $table_s AS s WHERE p.page_id=s.page_id AND s.module = 'menu_link'");
224
$table_mm = TABLE_PREFIX ."mod_menu_link";
225

  
226
$query_page = $database->query("SELECT p.*, s.section_id FROM $table_p AS p, $table_s AS s WHERE p.page_id=s.page_id AND s.module = 'menu_link'");
224 227
if($query_page->numRows() > 0) {
225 228
	while($page = $query_page->fetchRow()) {
226 229
		$pages[$page['page_id']]['page_details'] = $page;
......
258 261
		}
259 262
	}
260 263
}
264
unset($files); unset($dirs);
261 265
// try to convert old menu_links to new ones
262
$table_p = TABLE_PREFIX.'pages';
263
$table_s = TABLE_PREFIX.'sections';
264
$table_mm = TABLE_PREFIX ."mod_menu_link";
265 266
foreach($pages as $p) {
266 267
	$page = $p['page_details'];
267 268
	$file_content = $p['file_content'];
268 269
	$filename = $p['filename'];
269 270
	$link = $p['page_details']['link'];
270
	$page_trail = $p['page_details']['page_trail'];
271
	$parent_pid = $p['page_details']['parent'];
271 272
	$page_id = $p['page_details']['page_id'];
272
	//var_dump($page);var_dump($file_content);var_dump($filename);var_dump($link);var_dump($page_trail);
273
	$section_id = $p['page_details']['section_id'];
274
	$menu_title = $p['page_details']['menu_title'];
273 275

  
274
	// - aus wb_pages.page_trail aktuelle Position bestimmen
275
	// - daraus link bestimmen und in wb_pages eintragen
276
	// - Datei in pages wenn nötig verschieben
277
	//ok - Über $link die page_id der Zielseite feststellen (--> $target_page_id), und nach mod_menu_link speichern, anchor leer.
278
	if($query_pid = $database->query("SELECT p.page_id, s.section_id FROM $table_p AS p, $table_s AS s WHERE p.page_id = s.page_id AND p.link = '$link' AND p.page_id != '$page_id'")) {
276
	// calculate link from wb_pages.parent and menu_title
277
	$cur_link = '';
278
	if($parent_pid != '0' && $query_link = $database->query("SELECT link FROM $table_p WHERE page_id = '$parent_pid'")) {
279
		$res = $query_link->fetchRow();
280
		$cur_link .= $res['link'];
281
	}
282
	$cur_link .= '/'.page_filename($menu_title);
283
echo "found: $cur_link<br />";
284
	$database->query("UPDATE $table_p SET link = '$cur_link' WHERE page_id = '$page_id'");
285
	echo mysql_error()?'mySQL: '.mysql_error().'<br />':'';
286
	
287
	$new_filenames[$page_id]['file'] = WB_PATH.PAGES_DIRECTORY.$cur_link.PAGE_EXTENSION;
288
	$new_filenames[$page_id]['link'] = $cur_link;
289
	$new_filenames[$page_id]['menu'] = $menu_title;
290

  
291
	// delete old access files in pages
292
	if(file_exists($filename)) {
293
		if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
294
			echo "Cannot delete access file in pages/ - permission denied ($FAIL)<br />";
295
		} else {
296
			unlink($filename);
297
		}
298
	}
299
	
300
	// make entry in wb_mod_menu_link
301
	if($query_pid = $database->query("SELECT page_id FROM $table_p WHERE page_id != '$page_id' AND link = '$link'")) {
279 302
		$res = $query_pid->fetchRow();
280 303
		$target_page_id = $res['page_id'];
281
		$section_id = $res['section_id'];
282 304
		$database->query("INSERT INTO $table_mm (page_id, section_id, target_page_id, anchor) VALUES ('$page_id', '$section_id', '$target_page_id', '0')");
283
		echo mysql_error()?mysql_error().'<br />':'';
305
		echo mysql_error()?'mySQL: '.mysql_error().'<br />':'';
284 306
	}
285
//var_dump("-------------------");
286
	// This part is still missing
307
}
308
// create new access files in pages/; make directories as needed
309
foreach($pages as $p) {
310
	$page_id = $p['page_details']['page_id'];
311
	$filename = $new_filenames[$page_id]['file'];
312
	$menu_title = $new_filenames[$page_id]['menu'];
313
	$link = $new_filenames[$page_id]['link'];
314
	$content = $p['file_content'];
315
	$level = $p['page_details']['level'];
316
	$depth = '';
317
	for($i=0; $i<=$level; $i++)
318
		$depth .= '../';
319
	$content = preg_replace('#((../)+)config\.php#', "{$depth}config.php", $content);
320
	while(file_exists($filename)) {
321
		echo "Cannot create '$filename' - file exist. Renamed to: ";
322
		$menu_title .= '_';
323
		$link .= '_';
324
		$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
325
		echo "$filename<br />";
326
		$database->query("UPDATE $table_p SET link='$link', menu_title='$menu_title' WHERE page_id = '$page_id'");
327
		echo mysql_error()?'mySQL: '.mysql_error().'<br />':'';
328
	}
329
	// check if we need to create a subdir somewhere
330
	$dirs = array();
331
	while(dirname($link) != '/') {
332
		$link = dirname($link);
333
		$dirs[] = WB_PATH.PAGES_DIRECTORY.$link;
334
	}
335
	foreach(array_reverse($dirs) as $dir) {
336
		if(!file_exists($dir)) {
337
			mkdir($dir, OCTAL_DIR_MODE);
338
		}
339
	}
340
	// create new file in pages/
341
	if($handle=fopen($filename, "wb")) {
342
		if(!fwrite($handle, $content)) {
343
			echo "Cannot write to $filename - ($FAIL)<br />";
344
		}
345
		fclose($handle);
346
	} else {
347
		echo "Cannot create $filename - ($FAIL)<br />";
348
	}
349
	
350
}
287 351

  
288 352

  
289
}
290 353

  
291

  
292 354
//******************************************************************************
293 355
//Start of upgrade script for the form modul
294 356
//******************************************************************************

Also available in: Unified diff