? crazy.patch
? filter-notice-161351-1.patch
? filter_comments_head.patch
? php-disable-remove-format-161354.patch
? search_counting.patch.txt
? modules/filter/filter-notice-161351-1.patch
? sites/default/settings.php
? sites/default/settings.php2
Index: modules/php/php.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/php/php.install,v
retrieving revision 1.1
diff -u -p -r1.1 php.install
--- modules/php/php.install	24 Apr 2007 10:54:34 -0000	1.1
+++ modules/php/php.install	23 Jul 2007 06:12:28 -0000
@@ -2,15 +2,13 @@
 // $Id: php.install,v 1.1 2007/04/24 10:54:34 dries Exp $
 
 /**
- * Implementation of hook_install().
+ * Implementation of hook_enable().
  */
-function php_install() {
-  $format_exists = db_result(db_query("SELECT COUNT(*) FROM {filter_formats} WHERE name = 'PHP code'"));
-  // Add a PHP code input format, if it does not exist. Do this only for the
-  // first install (or if the format has been manually deleted) as there is no
-  // reliable method to identify the format in an uninstall hook or in
-  // subsequent clean installs.
-  if (!$format_exists) {
+function php_enable() {
+  $format = variable_get('php_format', 0); // db_result(db_query("SELECT format FROM {filter_formats} WHERE name = 'PHP code'"));
+
+  if (!$format) {
+    // Create PHP input format.
     db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('PHP code', '', 0)");
     $format = db_result(db_query("SELECT MAX(format) FROM {filter_formats}"));
 
@@ -18,6 +16,12 @@ function php_install() {
     db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, 'php', 0, 0)", $format);
 
     drupal_set_message(t('A !php-code input format has been created.', array('!php-code' => l('PHP code', 'admin/settings/filters/'. $format))));
+
+    variable_set('php_format', $format);
+  }
+  else {
+    // Replace PHP code format; module was disabled and re-enabled again.
+    db_query("INSERT INTO {filter_formats} (format, name, roles, cache) VALUES (%d, 'PHP code', '', 0)", $format);
   }
 }
 
@@ -25,5 +29,21 @@ function php_install() {
  * Implementation of hook_disable().
  */
 function php_disable() {
+  // Remove the PHP input format.
+  // TODO: Replace this with a nicer function call like filter_format_delete($format)
+  // when such a thing is available.
+  $form = array();
+  $form_state['values']['name'] = t('PHP code');
+  $form_state['values']['format'] = variable_get('php_format', 0);
+  filter_admin_delete_submit($form, $form_state);
+  db_query("DELETE FROM {filters} WHERE module = 'php'");
+
   drupal_set_message(t('The PHP module has been disabled. Please note that any existing content that was using the PHP filter will now be visible in plain text. This might pose a security risk by exposing sensitive information, if any, used in the PHP code.'));
 }
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function php_uninstall() {
+  variable_del('php_format');
+}
