- Timestamp:
- 04/16/10 16:51:19 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/dcAdvancedCleaner/inc/class.dc.advanced.cleaner.php
r1980 r2199 3 3 # This file is part of dcAdvancedCleaner, a plugin for Dotclear 2. 4 4 # 5 # Copyright (c) 2009 JC Denis and contributors5 # Copyright (c) 2009-2010 JC Denis and contributors 6 6 # jcdenis@gdwd.com 7 7 # … … 15 15 class dcAdvancedCleaner 16 16 { 17 protected static $errors = array( 18 'settings' => array( 19 'delete_global' => 'Failed to delete global settings', 20 'delete_local' => 'Failed to delete local settings', 21 'delete_all' => 'Failed to delete all settings' 22 ), 23 'tables' => array( 24 'empty' => 'Failed to empty table', 25 'delete' => 'Failed to delete table' 26 ), 27 'plugins' => array( 28 'empty' => 'Failed to empty plugin folder', 29 'delete' => 'Failed to delete plugin folder' 30 ), 31 'themes' => array( 32 'empty' => 'Failed to empty themes folder', 33 'delete' => 'Failed to delete themes folder' 34 ), 35 'caches' => array( 36 'empty' => 'Failed to empty cache folder', 37 'delete' => 'Failed to delete cache folder' 38 ), 39 'versions' => array( 40 'delete' => 'Failed to delete version' 41 ) 42 ); 43 17 44 public static $dotclear = array( 18 45 'settings' => array( … … 70 97 protected static function deleteGlobalSettings($core,$entry) 71 98 { 72 return$core->con->execute(99 $core->con->execute( 73 100 'DELETE FROM '.$core->prefix.'setting '. 74 101 'WHERE blog_id IS NULL '. 75 "AND setting_ns = '".$core->con->escape($entry)."' "); 102 "AND setting_ns = '".$core->con->escape($entry)."' " 103 ); 76 104 } 77 105 78 106 protected static function deleteLocalSettings($core,$entry) 79 107 { 80 return$core->con->execute(108 $core->con->execute( 81 109 'DELETE FROM '.$core->prefix.'setting '. 82 110 "WHERE blog_id = '".$core->con->escape($core->blog->id)."' ". 83 "AND setting_ns = '".$core->con->escape($entry)."' "); 111 "AND setting_ns = '".$core->con->escape($entry)."' " 112 ); 84 113 } 85 114 86 115 protected static function deleteAllSettings($core,$entry) 87 116 { 88 return$core->con->execute(117 $core->con->execute( 89 118 'DELETE FROM '.$core->prefix.'setting '. 90 119 "WHERE setting_ns = '".$core->con->escape($entry)."' ". 91 "AND (blog_id IS NULL OR blog_id != '') "); 120 "AND (blog_id IS NULL OR blog_id != '') " 121 ); 92 122 } 93 123 … … 99 129 $rs = array(); 100 130 $i = 0; 101 foreach($res as $v) { 102 103 $rs[$i]['key'] = substr($v,strlen($core->prefix)); 104 $rs[$i]['value'] = $core->con->select('SELECT count(*) FROM '.$v)->f(0); 131 foreach($res as $k => $v) 132 { 133 if ('' != $core->prefix) 134 { 135 if (!preg_match('/^'.$core->prefix.'/',$v)) continue; 136 $v = substr($v,strlen($core->prefix)); 137 } 138 $rs[$i]['key'] = $v; 139 $rs[$i]['value'] = $core->con->select('SELECT count(*) FROM '.$res[$k])->f(0); 105 140 $i++; 106 141 } … … 110 145 protected static function emptyTable($core,$entry) 111 146 { 112 return (boolean) $core->con->execute( 113 'DELETE FROM '.$core->con->escapeSystem($core->prefix.$entry)); 147 $core->con->execute( 148 'DELETE FROM '.$core->con->escapeSystem($core->prefix.$entry) 149 ); 114 150 } 115 151 116 152 protected static function deleteTable($core,$entry) 117 153 { 118 if (self::emptyTable($core,$entry)) {119 return (boolean) $core->con->execute( 120 'DROP TABLE '.$core->con->escapeSystem($core->prefix.$entry));121 }122 return false;154 self::emptyTable($core,$entry); 155 156 $core->con->execute( 157 'DROP TABLE '.$core->con->escapeSystem($core->prefix.$entry) 158 ); 123 159 } 124 160 … … 140 176 protected static function deleteVersion($core,$entry) 141 177 { 142 return (boolean)$core->con->execute(178 $core->con->execute( 143 179 'DELETE FROM '.$core->prefix.'version '. 144 "WHERE module = '".$core->con->escape($entry)."' "); 180 "WHERE module = '".$core->con->escape($entry)."' " 181 ); 145 182 } 146 183 … … 154 191 { 155 192 $res = explode(PATH_SEPARATOR,DC_PLUGINS_ROOT); 156 returnself::delDir($res,$entry,false);193 self::delDir($res,$entry,false); 157 194 } 158 195 … … 160 197 { 161 198 $res = explode(PATH_SEPARATOR,DC_PLUGINS_ROOT); 162 returnself::delDir($res,$entry,true);199 self::delDir($res,$entry,true); 163 200 } 164 201 … … 170 207 protected static function emptyTheme($core,$entry) 171 208 { 172 returnself::delDir($core->blog->themes_path,$entry,false);209 self::delDir($core->blog->themes_path,$entry,false); 173 210 } 174 211 175 212 protected static function deleteTheme($core,$entry) 176 213 { 177 returnself::delDir($core->blog->themes_path,$entry,true);214 self::delDir($core->blog->themes_path,$entry,true); 178 215 } 179 216 … … 185 222 protected static function emptyCache($core,$entry) 186 223 { 187 returnself::delDir(DC_TPL_CACHE,$entry,false);224 self::delDir(DC_TPL_CACHE,$entry,false); 188 225 } 189 226 190 227 protected static function deleteCache($core,$entry) 191 228 { 192 returnself::delDir(DC_TPL_CACHE,$entry,true);229 self::delDir(DC_TPL_CACHE,$entry,true); 193 230 } 194 231 … … 201 238 $core->callBehavior('dcAdvancedCleanerBeforeAction',$type,$action,$ns); 202 239 203 # Delete global settings 204 if ($type == 'settings' && $action == 'delete_global') 205 self::deleteGlobalSettings($core,$ns); 206 207 # Delete local settings 208 if ($type == 'settings' && $action == 'delete_local') 209 self::deleteLocalSettings($core,$ns); 210 211 # Delete all settings 212 if ($type == 'settings' && $action == 'delete_all') 213 self::deleteAllSettings($core,$ns); 214 215 # Empty tables 216 if ($type == 'tables' && $action == 'empty') 217 self::emptyTable($core,$ns); 218 219 # Delete tables 220 if ($type == 'tables' && $action == 'delete') 221 self::deleteTable($core,$ns); 222 223 # Delete versions 224 if ($type == 'versions' && $action == 'delete') 225 self::deleteVersion($core,$ns); 226 227 # Empty plugins 228 if ($type == 'plugins' && $action == 'empty') 229 self::emptyPlugin($core,$ns); 230 231 # Delete plugins 232 if ($type == 'plugins' && $action == 'delete') 233 self::deletePlugin($core,$ns); 234 235 # Empty themes 236 if ($type == 'themes' && $action == 'empty') 237 self::emptyTheme($core,$ns); 238 239 # Delete themes 240 if ($type == 'themes' && $action == 'delete') 241 self::deleteTheme($core,$ns); 242 243 # Empty caches 244 if ($type == 'caches' && $action == 'empty') 245 self::emptyCache($core,$ns); 246 247 # Delete caches 248 if ($type == 'caches' && $action == 'delete') 249 self::deleteCache($core,$ns); 240 try { 241 # Delete global settings 242 if ($type == 'settings' && $action == 'delete_global') 243 self::deleteGlobalSettings($core,$ns); 244 245 # Delete local settings 246 if ($type == 'settings' && $action == 'delete_local') 247 self::deleteLocalSettings($core,$ns); 248 249 # Delete all settings 250 if ($type == 'settings' && $action == 'delete_all') 251 self::deleteAllSettings($core,$ns); 252 253 # Empty tables 254 if ($type == 'tables' && $action == 'empty') 255 self::emptyTable($core,$ns); 256 257 # Delete tables 258 if ($type == 'tables' && $action == 'delete') 259 self::deleteTable($core,$ns); 260 261 # Delete versions 262 if ($type == 'versions' && $action == 'delete') 263 self::deleteVersion($core,$ns); 264 265 # Empty plugins 266 if ($type == 'plugins' && $action == 'empty') 267 self::emptyPlugin($core,$ns); 268 269 # Delete plugins 270 if ($type == 'plugins' && $action == 'delete') 271 self::deletePlugin($core,$ns); 272 273 # Empty themes 274 if ($type == 'themes' && $action == 'empty') 275 self::emptyTheme($core,$ns); 276 277 # Delete themes 278 if ($type == 'themes' && $action == 'delete') 279 self::deleteTheme($core,$ns); 280 281 # Empty caches 282 if ($type == 'caches' && $action == 'empty') 283 self::emptyCache($core,$ns); 284 285 # Delete caches 286 if ($type == 'caches' && $action == 'delete') 287 self::deleteCache($core,$ns); 288 289 return true; 290 } 291 catch(Exception $e) { 292 $errors = self::$errors; 293 if (isset($errors[$type][$action])) { 294 throw new Exception(__($errors[$type][$action])); 295 } 296 else { 297 throw new Exception(sprintf(__('Cannot execute "%s" of type "%s"'),$action,$type)); 298 } 299 return false; 300 } 250 301 } 251 302 … … 314 365 protected static function delTree($dir,$delroot=true) 315 366 { 316 $current_dir = opendir($dir); 317 while($entryname = readdir($current_dir)) { 318 319 if (is_dir($dir.'/'.$entryname) && ($entryname != '.' && $entryname!='..')) { 320 321 if (!self::delTree($dir.'/'.$entryname)) return false; 322 } 323 elseif ($entryname != '.' && $entryname!='..') { 324 325 if (!@unlink($dir.'/'.$entryname)) return false; 326 } 327 } 328 closedir($current_dir); 367 if (!is_dir($dir) || !is_readable($dir)) return false; 368 369 if (substr($dir,-1) != '/') $dir .= '/'; 370 371 if (($d = @dir($dir)) === false) return false; 372 373 while (($entryname = $d->read()) !== false) 374 { 375 if ($entryname != '.' && $entryname != '..') 376 { 377 if (is_dir($dir.'/'.$entryname)) 378 { 379 if (!self::delTree($dir.'/'.$entryname)) return false; 380 } 381 else 382 { 383 if (!@unlink($dir.'/'.$entryname)) return false; 384 } 385 } 386 } 387 $d->close(); 329 388 330 389 if ($delroot)
Note: See TracChangeset
for help on using the changeset viewer.