Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
resync.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\attachment;
015
016 use \phpbb\db\driver\driver_interface;
017
018 /**
019 * Attachment resync class
020 */
021 class resync
022 {
023 /** @var driver_interface */
024 protected $db;
025
026 /** @var string Attachment table SQL ID */
027 private $attach_sql_id;
028
029 /** @var string Resync table SQL ID */
030 private $resync_sql_id;
031
032 /** @var string Resync SQL table */
033 private $resync_table;
034
035 /** @var string SQL where statement */
036 private $sql_where;
037
038 /**
039 * Constructor for attachment resync class
040 *
041 * @param driver_interface $db Database driver
042 */
043 public function __construct(driver_interface $db)
044 {
045 $this->db = $db;
046 }
047
048 /**
049 * Set type constraints for attachment resync
050 *
051 * @param string $type Type of resync; can be: message|post|topic
052 */
053 protected function set_type_constraints($type)
054 {
055 switch ($type)
056 {
057 case 'message':
058 $this->attach_sql_id = 'post_msg_id';
059 $this->sql_where = ' AND in_message = 1
060 AND is_orphan = 0';
061 $this->resync_table = PRIVMSGS_TABLE;
062 $this->resync_sql_id = 'msg_id';
063 break;
064
065 case 'post':
066 $this->attach_sql_id = 'post_msg_id';
067 $this->sql_where = ' AND in_message = 0
068 AND is_orphan = 0';
069 $this->resync_table = POSTS_TABLE;
070 $this->resync_sql_id = 'post_id';
071 break;
072
073 case 'topic':
074 $this->attach_sql_id = 'topic_id';
075 $this->sql_where = ' AND is_orphan = 0';
076 $this->resync_table = TOPICS_TABLE;
077 $this->resync_sql_id = 'topic_id';
078 break;
079 }
080 }
081
082 /**
083 * Resync specified type
084 *
085 * @param string $type Type of resync
086 * @param array $ids IDs to resync
087 */
088 public function resync($type, $ids)
089 {
090 if (empty($type) || !is_array($ids) || !sizeof($ids) || !in_array($type, array('post', 'topic', 'message')))
091 {
092 return;
093 }
094
095 $this->set_type_constraints($type);
096
097 // Just check which elements are still having an assigned attachment
098 // not orphaned by querying the attachments table
099 $sql = 'SELECT ' . $this->attach_sql_id . '
100 FROM ' . ATTACHMENTS_TABLE . '
101 WHERE ' . $this->db->sql_in_set($this->attach_sql_id, $ids)
102 . $this->sql_where;
103 $result = $this->db->sql_query($sql);
104
105 $remaining_ids = array();
106 while ($row = $this->db->sql_fetchrow($result))
107 {
108 $remaining_ids[] = $row[$this->attach_sql_id];
109 }
110 $this->db->sql_freeresult($result);
111
112 // Now only unset those ids remaining
113 $ids = array_diff($ids, $remaining_ids);
114
115 if (sizeof($ids))
116 {
117 $sql = 'UPDATE ' . $this->resync_table . '
118 SET ' . $type . '_attachment = 0
119 WHERE ' . $this->db->sql_in_set($this->resync_sql_id, $ids);
120 $this->db->sql_query($sql);
121 }
122 }
123
124 }
125