[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/phpbb/db/migration/data/v310/ -> soft_delete_mod_convert.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\db\migration\data\v310;
  15  
  16  use phpbb\db\migration\container_aware_migration;
  17  
  18  /**
  19   * Migration to convert the Soft Delete MOD for 3.0
  20   *
  21   * https://www.phpbb.com/customise/db/mod/soft_delete/
  22   */
  23  class soft_delete_mod_convert extends container_aware_migration
  24  {
  25  	static public function depends_on()
  26      {
  27          return array(
  28              '\phpbb\db\migration\data\v310\alpha3',
  29          );
  30      }
  31  
  32  	public function effectively_installed()
  33      {
  34          return !$this->db_tools->sql_column_exists($this->table_prefix . 'posts', 'post_deleted');
  35      }
  36  
  37  	public function update_data()
  38      {
  39          return array(
  40              array('permission.remove', array('m_harddelete', true)),
  41              array('permission.remove', array('m_harddelete', false)),
  42  
  43              array('custom', array(array($this, 'convert_posts'))),
  44              array('custom', array(array($this, 'convert_topics'))),
  45          );
  46      }
  47  
  48  	public function convert_posts($start)
  49      {
  50          $content_visibility = $this->get_content_visibility();
  51  
  52          $limit = 250;
  53          $i = 0;
  54  
  55          $sql = 'SELECT p.*, t.topic_first_post_id, t.topic_last_post_id
  56              FROM ' . $this->table_prefix . 'posts p, ' . $this->table_prefix . 'topics t
  57              WHERE p.post_deleted > 0
  58                  AND t.topic_id = p.topic_id';
  59          $result = $this->db->sql_query_limit($sql, $limit, $start);
  60  
  61          while ($row = $this->db->sql_fetchrow($result))
  62          {
  63              $content_visibility->set_post_visibility(
  64                  ITEM_DELETED,
  65                  $row['post_id'],
  66                  $row['topic_id'],
  67                  $row['forum_id'],
  68                  $row['post_deleted'],
  69                  $row['post_deleted_time'],
  70                  '',
  71                  ($row['post_id'] == $row['topic_first_post_id']) ? true : false,
  72                  ($row['post_id'] == $row['topic_last_post_id']) ? true : false
  73              );
  74  
  75              $i++;
  76          }
  77  
  78          $this->db->sql_freeresult($result);
  79  
  80          if ($i == $limit)
  81          {
  82              return $start + $i;
  83          }
  84      }
  85  
  86  	public function convert_topics($start)
  87      {
  88          $content_visibility = $this->get_content_visibility();
  89  
  90          $limit = 100;
  91          $i = 0;
  92  
  93          $sql = 'SELECT *
  94              FROM ' . $this->table_prefix . 'topics
  95              WHERE topic_deleted > 0';
  96          $result = $this->db->sql_query_limit($sql, $limit, $start);
  97  
  98          while ($row = $this->db->sql_fetchrow($result))
  99          {
 100              $content_visibility->set_topic_visibility(
 101                  ITEM_DELETED,
 102                  $row['topic_id'],
 103                  $row['forum_id'],
 104                  $row['topic_deleted'],
 105                  $row['topic_deleted_time'],
 106                  ''
 107              );
 108  
 109              $i++;
 110          }
 111  
 112          $this->db->sql_freeresult($result);
 113  
 114          if ($i == $limit)
 115          {
 116              return $start + $i;
 117          }
 118      }
 119  
 120      /**
 121       * @return \phpbb\content_visibility
 122       */
 123  	protected function get_content_visibility()
 124      {
 125          return $this->container->get('content.visibility');
 126      }
 127  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1