PageRenderTime 34ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/maintenance/deleteImageMemcached.php

https://bitbucket.org/ghostfreeman/freeside-wiki
PHP | 81 lines | 39 code | 13 blank | 29 comment | 4 complexity | 9e59cf389d950d19f34e60d95f75e461 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, LGPL-3.0
  1. <?php
  2. /**
  3. * Delete image information from the object cache.
  4. *
  5. * Usage example:
  6. * php deleteImageMemcached.php --until "2005-09-05 00:00:00" --sleep 0
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. * http://www.gnu.org/copyleft/gpl.html
  22. *
  23. * @file
  24. * @ingroup Maintenance
  25. */
  26. require_once( __DIR__ . '/Maintenance.php' );
  27. /**
  28. * Maintenance script that deletes image information from the object cache.
  29. *
  30. * @ingroup Maintenance
  31. */
  32. class DeleteImageCache extends Maintenance {
  33. public function __construct() {
  34. parent::__construct();
  35. $this->mDescription = "Delete image information from the cache";
  36. $this->addOption( 'sleep', 'How many seconds to sleep between deletions', true, true );
  37. $this->addOption( 'until', 'Timestamp to delete all entries prior to', true, true );
  38. }
  39. public function execute() {
  40. global $wgMemc;
  41. $until = preg_replace( "/[^\d]/", '', $this->getOption( 'until' ) );
  42. $sleep = (int)$this->getOption( 'sleep' ) * 1000; // milliseconds
  43. ini_set( 'display_errors', false );
  44. $dbr = wfGetDB( DB_SLAVE );
  45. $res = $dbr->select( 'image',
  46. array( 'img_name' ),
  47. array( "img_timestamp < {$until}" ),
  48. __METHOD__
  49. );
  50. $i = 0;
  51. $total = $this->getImageCount();
  52. foreach ( $res as $row ) {
  53. if ( $i % $this->report == 0 )
  54. $this->output( sprintf( "%s: %13s done (%s)\n", wfWikiID(), "$i/$total", wfPercent( $i / $total * 100 ) ) );
  55. $md5 = md5( $row->img_name );
  56. $wgMemc->delete( wfMemcKey( 'Image', $md5 ) );
  57. if ( $sleep != 0 )
  58. usleep( $sleep );
  59. ++$i;
  60. }
  61. }
  62. private function getImageCount() {
  63. $dbr = wfGetDB( DB_SLAVE );
  64. return $dbr->selectField( 'image', 'COUNT(*)', array(), __METHOD__ );
  65. }
  66. }
  67. $maintClass = "DeleteImageCache";
  68. require_once( RUN_MAINTENANCE_IF_MAIN );