[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/dao/ -> purgedata.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
   4      
   5      define( "DEFAULT_PURGE_AMOUNT", 15 );
   6  
   7      /**
   8       * This class takes care of purging data, since it's a very complex process anyway
   9       */
  10      class PurgeData extends Blogs
  11      {
  12          /**
  13           * Deletes a blog and all its data
  14           *
  15           * @param blogId The id of the blog whose data we'd like to delete
  16           */
  17  		function deleteBlogData( $blogId )
  18          {
  19              // delete the article categories
  20              lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
  21              $cats = new ArticleCategories();
  22              $cats->deleteBlogCategories( $blogId );
  23              // article notifications
  24              lt_include( PLOG_CLASS_PATH."class/dao/articlenotifications.class.php" );
  25              $notifications = new ArticleNotifications();
  26              $notifications->deleteBlogNotifications( $blogId );            
  27              // comments
  28              lt_include( PLOG_CLASS_PATH."class/dao/commentscommon.class.php" );
  29              $comments = new CommentsCommon();
  30              $comments->deleteBlogComments( $blogId );
  31              // links
  32              lt_include( PLOG_CLASS_PATH."class/dao/mylinks.class.php" );            
  33              $links = new MyLinks();
  34              $links->deleteBlogMyLinks( $blogId );
  35              // link categories
  36              lt_include( PLOG_CLASS_PATH."class/dao/mylinkscategories.class.php" );
  37              $links = new MyLinksCategories();
  38              $links->deleteBlogMyLinksCategories( $blogId );
  39              // referers
  40              lt_include( PLOG_CLASS_PATH."class/dao/referers.class.php" );            
  41              $referers = new Referers();
  42              $referers->deleteBlogReferers( $blogId );
  43              // permissions
  44              lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );            
  45              $perms = new UserPermissions();
  46              $perms->revokeBlogPermissions( $blogId );
  47              // resources
  48              lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" );
  49              $albums = new GalleryResources();
  50              $albums->deleteUserResources( $blogId );
  51              // albums
  52              lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );            
  53              $albums = new GalleryAlbums();
  54              $albums->deleteUserAlbums( $blogId );                        
  55              // articles
  56              lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
  57              $articles = new Articles();
  58              $articles->deleteBlogPosts( $blogId );
  59              // the blog itself
  60              lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
  61              $blogs = new Blogs();
  62              $blogs->deleteBlog( $blogId );
  63  
  64              // reset the template cache
  65              CacheControl::resetBlogCache( $blogId, false );
  66          }
  67          
  68          /**
  69           * removes all blogs that have 'deleted' status
  70           *
  71           * @return Returns     how many we purged, and when this method returns '0', it means that there is nothing else
  72           * left to be purged
  73           */        
  74          function purgeBlogs( $amount = DEFAULT_PURGE_AMOUNT)
  75          {                                  
  76              $disabledBlogs = $this->getAllBlogs( BLOG_STATUS_DISABLED, ALL_BLOG_CATEGORIES, "", 1, $amount );
  77              foreach( $disabledBlogs as $blog ) {
  78                  $blogId = $blog->getId();
  79                  $this->deleteBlogData( $blogId );
  80              }
  81              
  82              return( count( $disabledBlogs ));
  83          }
  84  
  85          /**
  86           * Purge spam comments
  87           *
  88           * @param amount
  89           * @return Returns false on error, or else number of comments purged,
  90           *   if 0, there is nothing left to purge
  91           */
  92  		function purgeSpamComments( $amount = DEFAULT_PURGE_AMOUNT )
  93          {
  94              lt_include( PLOG_CLASS_PATH."class/dao/commentscommon.class.php" );
  95              
  96              $query = "SELECT id FROM ".$this->getPrefix()."articles_comments WHERE status = ".COMMENT_STATUS_SPAM." LIMIT 0, $amount";
  97              $result = $this->Execute( $query );
  98              
  99              if( !$result )
 100                  return false;
 101                  
 102              $deleted = 0;
 103              $comments = new CommentsCommon();
 104              
 105              while( $row = $result->FetchRow()) {
 106                  // the CommentsCommon::deleteComment() method should take care of updating the articles,
 107                  // resettings caches and updating comment counters in articles and blogs
 108                  $comments->deleteComment( $row["id"] );
 109                  $deleted++;
 110              }
 111              
 112              return( $deleted );
 113          }
 114          
 115          /**
 116           * Purge articles that have been marked as deleted
 117           *
 118           * @return Returns false on error, or else number of posts purged,
 119           *   if 0, there is nothing left to purge
 120           *
 121           * @param amount
 122           */
 123  		function purgePosts( $amount = DEFAULT_PURGE_AMOUNT ) 
 124          {
 125              lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
 126              
 127              $query = "SELECT id, user_id, blog_id  FROM ".$this->getPrefix()."articles WHERE status = ".POST_STATUS_DELETED." LIMIT 0, $amount";
 128              
 129              $result = $this->Execute( $query );
 130              
 131              if( !$result )
 132                  return false;
 133                  
 134              $deleted = 0;
 135              $posts = new Articles();
 136              
 137              while( $row = $result->FetchRow()) {
 138                  // calling the method in the Articles class will take care of everything else
 139                  $posts->deleteArticle( $row["id"], $row["user_id"], $row["blog_id"], true );
 140                  $deleted++;
 141              }
 142              
 143              return( $deleted );            
 144          }
 145          
 146          /**
 147           * Purge users that have been marked as disabled. If these users own a
 148           * blog, then the blog will also be removed
 149           *
 150           * @return Returns number of users purged,
 151           *   if 0, there is nothing left to purge
 152           *
 153           * @param amount
 154           */
 155  		function purgeUsers( $amount = DEFAULT_PURGE_AMOUNT )
 156          {
 157              lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
 158  
 159              $users = new Users();
 160              $deleted = 0;
 161              // get $amount more users...
 162              $disabledUsers = $users->getAllUsers( USER_STATUS_DISABLED, "", "", 1, $amount );
 163              // and process them
 164              foreach( $disabledUsers as $user ) {
 165                  foreach( $user->getOwnBlogs() as $userBlog ) {                    
 166                      $this->deleteBlogData( $userBlog->getId());
 167                  }
 168                  
 169                  $users->deleteUser( $user->getId());
 170                  $deleted++;
 171              }
 172              
 173              return( $deleted );            
 174          }
 175      }
 176  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics