diff options
| author | Joas Schilling <nickvergessen@gmx.de> | 2011-01-27 14:23:33 +0100 | 
|---|---|---|
| committer | Joas Schilling <nickvergessen@gmx.de> | 2011-02-08 14:57:43 +0100 | 
| commit | 65020fd5c1d71f44ef74824a27eaf4929b19635c (patch) | |
| tree | 5cce85c3b9dd611936928abf634f81d146ece996 | |
| parent | 0e02f5cb0b7f615f1eadd6606a89bfd1b28f0d0d (diff) | |
| download | forums-65020fd5c1d71f44ef74824a27eaf4929b19635c.tar forums-65020fd5c1d71f44ef74824a27eaf4929b19635c.tar.gz forums-65020fd5c1d71f44ef74824a27eaf4929b19635c.tar.bz2 forums-65020fd5c1d71f44ef74824a27eaf4929b19635c.tar.xz forums-65020fd5c1d71f44ef74824a27eaf4929b19635c.zip | |
[ticket/9675] Correctly check whether the style/component is still in use.
And don't allow to delete it in that case.
PHPBB3-9675
| -rw-r--r-- | phpBB/includes/acp/acp_styles.php | 92 | 
1 files changed, 64 insertions, 28 deletions
| diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 2e2807c8cb..0f157ceff3 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -1662,7 +1662,7 @@ parse_css_file = {PARSE_CSS_FILE}  				{  					$new_id = request_var('new_' . $component . '_id', 0);  					$component_id = $style_row[$component . '_id']; -					$this->remove_component($component, $component_id, $new_id); +					$this->remove_component($component, $component_id, $new_id, $style_id);  				}  			}  			else @@ -1708,20 +1708,32 @@ parse_css_file = {PARSE_CSS_FILE}  	/**  	* Remove template/theme/imageset entry from the database  	*/ -	function remove_component($component, $style_id, $new_id) +	function remove_component($component, $component_id, $new_id, $style_id = false)  	{  		global $db; -		if (($new_id == 0) || ($component === 'template' && ($conflicts = $this->check_inheritance($component, $style_id)))) +		if (($new_id == 0) || ($component === 'template' && ($conflicts = $this->check_inheritance($component, $component_id))))  		{ -			// We can not delete the template, as the selected one is inheriting from this one. +			// We can not delete the template, as the user wants to keep the component or an other template is inheriting from this one. +			return; +		} + +		$component_in_use = array(); +		if ($component != 'style') +		{ +			$component_in_use = $this->component_in_use($component, $component_id, $style_id); +		} + +		if (($new_id == -1) && !empty($component_in_use)) +		{ +			// We can not delete the component, as it is still in use  			return;  		}  		if ($component == 'imageset')  		{  			$sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . " -				WHERE imageset_id = $style_id"; +				WHERE imageset_id = $component_id";  			$db->sql_query($sql);  		} @@ -1741,12 +1753,12 @@ parse_css_file = {PARSE_CSS_FILE}  		}  		$sql = "DELETE FROM $sql_from -			WHERE {$component}_id = $style_id"; +			WHERE {$component}_id = $component_id";  		$db->sql_query($sql);  		$sql = 'UPDATE ' . STYLES_TABLE . "  			SET {$component}_id = $new_id -			WHERE {$component}_id = $style_id"; +			WHERE {$component}_id = $component_id";  		$db->sql_query($sql);  	} @@ -1758,27 +1770,9 @@ parse_css_file = {PARSE_CSS_FILE}  		global $db, $template, $user;  		$component_in_use = array(); -		if (($component != 'style') && $style_id) +		if ($component != 'style')  		{ -			$sql = 'SELECT style_id, style_name -				FROM ' . STYLES_TABLE . " -				WHERE {$component}_id = {$component_id} -					AND style_id <> {$style_id} -				ORDER BY style_name ASC"; -			$result = $db->sql_query($sql); -			while ($row = $db->sql_fetchrow($result)) -			{ -				$component_in_use[] = $row['style_name']; -			} -			$db->sql_freeresult($result); - -			if ($component === 'template' && ($conflicts = $this->check_inheritance($component, $component_id))) -			{ -				foreach ($conflicts as $temp_id => $conflict_data) -				{ -					$component_in_use[] = $conflict_data['template_name']; -				} -			} +			$component_in_use = $this->component_in_use($component, $component_id, $style_id);  		}  		$sql_where = ''; @@ -1852,13 +1846,55 @@ parse_css_file = {PARSE_CSS_FILE}  				$components = array('template', 'theme', 'imageset');  				foreach ($components as $component)  				{ -					$this->display_component_options($component, $style_row[$component . '_id'], false, $component_id); +					$this->display_component_options($component, $style_row[$component . '_id'], false, $component_id, true);  				}  			}  		}  	}  	/** +	* Check whether the component is still used by another style or component +	*/ +	function component_in_use($component, $component_id, $style_id = false) +	{ +		global $db; + +		$component_in_use = array(); + +		if ($style_id) +		{ +			$sql = 'SELECT style_id, style_name +				FROM ' . STYLES_TABLE . " +				WHERE {$component}_id = {$component_id} +					AND style_id <> {$style_id} +				ORDER BY style_name ASC"; +		} +		else +		{ +			$sql = 'SELECT style_id, style_name +				FROM ' . STYLES_TABLE . " +				WHERE {$component}_id = {$component_id} +				ORDER BY style_name ASC"; +		} +		$result = $db->sql_query($sql); +		while ($row = $db->sql_fetchrow($result)) +		{ +			$component_in_use[] = $row['style_name']; +		} +		$db->sql_freeresult($result); + +		if ($component === 'template' && ($conflicts = $this->check_inheritance($component, $component_id))) +		{ +			foreach ($conflicts as $temp_id => $conflict_data) +			{ +				$component_in_use[] = $conflict_data['template_name']; +			} +		} + +		return $component_in_use; +	} + +	/**  	* Export style or style elements  	*/  	function export($mode, $style_id) | 
