[4611] trunk/htdocs/system/classes/plugins.php: Add a $force option to plugin deactivation, which forces a plugin to be deactivated, regardless of what other plugins say.

0 views
Skip to first unread message

svn-N...@habariproject.org

unread,
Nov 22, 2010, 1:24:29 PM11/22/10
to habar...@googlegroups.com
Revision
4611
Author
chrismeller
Date
2010-11-22 18:24:26 +0000 (Mon, 22 Nov 2010)

Log Message

Add a $force option to plugin deactivation, which forces a plugin to be deactivated, regardless of what other plugins say.

When loading active plugins, if the file does not exist, forcibly deactivate the plugin. If you don't, a broken plugin could randomly pop back up as active if you move it back to its original location. I'm wiling to bet we all have old plugins in the list that we wouldn't want to magically reappear as soon as their files show back up.

Modified Paths

Diff

Modified: trunk/htdocs/system/classes/plugins.php (4610 => 4611)


--- trunk/htdocs/system/classes/plugins.php	2010-11-22 04:47:14 UTC (rev 4610)
+++ trunk/htdocs/system/classes/plugins.php	2010-11-22 18:24:26 UTC (rev 4611)
@@ -256,6 +256,11 @@
 					if ( file_exists( $filename ) ) {
 						self::$plugin_files[$class] = $filename;
 					}
+					else {
+						// file does not exist, deactivate plugin
+						self::deactivate_plugin($filename, true);
+						EventLog::log( _t('Plugin "%1$s" deactivated because it could no longer be found.', array( $class ) ), 'err', 'plugin', 'habari', $filename );
+					}
 				}
 			}
 			// make sure things work on Windows
@@ -485,12 +490,12 @@
 	/**
 	 * Deactivates a plugin file
 	 */
-	public static function deactivate_plugin( $file )
+	public static function deactivate_plugin( $file, $force = false )
 	{
 		$ok = true;
 		$name = '';
 		$ok = Plugins::filter('deactivate_plugin', $ok, $file);  // Allow plugins to reject deactivation
-		if ( $ok ) {
+		if ( $ok || $force == true ) {
 			// normalize directory separator
 			$file = str_replace( '\\', '/', $file );
 			// strip base path from stored path
@@ -499,18 +504,32 @@
 			$activated = Options::get( 'active_plugins' );
 			$index = array_search( $short_file, $activated );
 			if ( is_array( $activated ) && ( false !== $index ) ) {
-				// Get plugin name for logging
-				$name = self::$plugins[Plugins::id_from_file( $file )]->info->name;
-				if ( method_exists(self::$plugins[Plugins::id_from_file( $file )], 'action_plugin_deactivation') ) {
-					self::$plugins[Plugins::id_from_file( $file )]->action_plugin_deactivation( $file ); // For the plugin to uninstall itself
+				
+				if ( $force != true ) {
+					// Get plugin name for logging
+					$name = self::$plugins[Plugins::id_from_file( $file )]->info->name;
+					if ( method_exists(self::$plugins[Plugins::id_from_file( $file )], 'action_plugin_deactivation') ) {
+						self::$plugins[Plugins::id_from_file( $file )]->action_plugin_deactivation( $file ); // For the plugin to uninstall itself
+					}
 				}
+				
 				unset($activated[$index]);
 				Options::set( 'active_plugins', $activated );
-				Plugins::act('plugin_deactivated', $file);  // For other plugins to react to a plugin uninstallation
-				EventLog::log( _t( 'Deactivated Plugin: %s', array( $name ) ), 'notice', 'plugin', 'habari' );
+				
+				if ( $force != true ) {
+					Plugins::act('plugin_deactivated', $file);  // For other plugins to react to a plugin uninstallation
+					EventLog::log( _t( 'Deactivated Plugin: %s', array( $name ) ), 'notice', 'plugin', 'habari' );
+				}
 			}
 		}
-		return $ok;
+		
+		if ( $force == true ) {
+			// always return true for forced deactivations
+			return true;
+		}
+		else {
+			return $ok;
+		}
 	}
 
 	/**
Reply all
Reply to author
Forward
0 new messages