Project

General

Profile

« Previous | Next » 

Revision 54

Added by stefan about 19 years ago

Fixed bug #2 - Issue when changing page parent

View differences:

settings2.php
172 172
		}
173 173
		// Update any pages that had the old link with the new one
174 174
		$old_link_len = strlen($old_link);
175
		$query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%'");
175
		$query_subs = $database->query("SELECT page_id,link,level FROM ".TABLE_PREFIX."pages WHERE link LIKE '%$old_link/%' ORDER BY LEVEL ASC");
176 176
		if($query_subs->numRows() > 0) {
177 177
			while($sub = $query_subs->fetchRow()) {
178 178
				// Double-check to see if it contains old link
179 179
				if(substr($sub['link'], 0, $old_link_len) == $old_link) {
180 180
					// Get new link
181 181
					$replace_this = $old_link;
182
					$with_this = $link;
183
					$old_value = $sub['link'];
184
					$new_value = '';
185
					$explode = explode('/',$old_value);
186
					$replaced = false;
187
					foreach($explode AS $exploded) {
188
						if($exploded != '') {
189
							$exploded_value = '/'.$exploded;
190
							if($replaced != true AND strstr($exploded_value,$replace_this) != '') {
191
								$new_value .= str_replace($replace_this,$with_this,$exploded_value);
192
								$replaced = true;
193
							} else {
194
								$new_value .= $exploded_value;
195
							}
196
						}
197
					}
198
					$new_sub_link = $new_value;
182
					$old_sub_link_len =strlen($sub['link']);
183
					$new_sub_link = $link.'/'.substr($sub['link'],$old_link_len+1,$old_sub_link_len);
199 184
					// Work out level
200 185
					$new_sub_level = level_count($sub['page_id']);
201
					// If level has changed update level as well as link
202
					if($new_sub_level != $sub['level']) {
203
						// Update level and link
204
						$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
205
					} else {
206
						// Update link
207
						$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
208
					}
186
					// Update level and link
187
					$database->query("UPDATE ".TABLE_PREFIX."pages SET link = '$new_sub_link', level = '$new_sub_level' WHERE page_id = '".$sub['page_id']."' LIMIT 1");
209 188
					// Re-write the access file for this page
210
					$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$sub['link'].'.php';
189
					$old_subpage_file = WB_PATH.PAGES_DIRECTORY.$new_sub_link.'.php';
211 190
					if(file_exists($old_subpage_file)) {
212 191
						unlink($old_subpage_file);
213 192
					}

Also available in: Unified diff