From e241e9dccf36ddef96ccf2b48c6d002b3ceb53f8 Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Tue, 19 Jul 2011 21:14:13 +0000
Subject: [PATCH] [gh-172] Merging from testing into staging

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@866 20a16fea-79d4-4915-8869-1ea9d5ebf173
---
 sites/all/modules/unl/cron.php | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/sites/all/modules/unl/cron.php b/sites/all/modules/unl/cron.php
index eaebd21e..fa18e461 100644
--- a/sites/all/modules/unl/cron.php
+++ b/sites/all/modules/unl/cron.php
@@ -219,7 +219,7 @@ function unl_add_site($site_path, $uri, $clean_url, $db_prefix, $site_id) {
   if ($site_mail) {
     $command .= " --site-mail=$site_mail"; 
   }
-  shell_exec($command);
+  echo shell_exec($command);
   
   unl_add_site_to_htaccess($site_id, $site_path, FALSE);
   
@@ -227,7 +227,8 @@ function unl_add_site($site_path, $uri, $clean_url, $db_prefix, $site_id) {
 }
 
 function unl_remove_site($site_path, $uri, $db_prefix, $site_id) {
-  $schema = drupal_get_schema();
+  // Grab the list of tables we need to drop.
+  $schema = drupal_get_schema(NULL, TRUE);
   $tables = array_keys($schema);
   sort($tables);
     
@@ -248,6 +249,7 @@ function unl_remove_site($site_path, $uri, $db_prefix, $site_id) {
     return FALSE;
   }
 
+  // Drop the site's tables
   foreach ($tables as $table) {
     $table = $db_prefix . $table;
     try {
@@ -257,26 +259,17 @@ function unl_remove_site($site_path, $uri, $db_prefix, $site_id) {
     }
   }
   
+  // Do our best to remove the sites
   shell_exec('chmod -R u+w ' . escapeshellarg($sites_subdir));
   shell_exec('rm -rf ' . escapeshellarg($sites_subdir));
   
   // Remove the rewrite rules from .htaccess for this site.
-  $htaccess = file_get_contents(DRUPAL_ROOT . '/.htaccess');
-  $site_start_token = "\n  # %UNL_START_SITE_ID_$site_id%";
-  $site_end_token = "  # %UNL_END_SITE_ID_$site_id%\n";
-  
-  $start_pos = strpos($htaccess, $site_start_token);
-  $end_pos = strpos($htaccess, $site_end_token);
+  unl_remove_site_from_htaccess($site_id, FALSE);
   
-  if ($start_pos === FALSE || $end_pos === FALSE) {
-    return FALSE;
+  // If we were using memcache, flush its cache so new sites don't have stale data.
+  if (class_exists('MemCacheDrupal', FALSE)) {
+    dmemcache_flush();
   }
-  $new_htaccess = substr($htaccess, 0, $start_pos)
-                . substr($htaccess, $end_pos + strlen($site_end_token))
-                ;
-  file_put_contents(DRUPAL_ROOT . '/.htaccess', $new_htaccess);
-  
-  unl_remove_site_from_htaccess($site_id, FALSE);
   
   return TRUE;
 }
-- 
GitLab