Index: branches/liquidthreads/maintenance/lqt.sql |
— | — | @@ -4,12 +4,13 @@ |
5 | 5 | thread_article int(8) unsigned NOT NULL, |
6 | 6 | thread_path text NOT NULL, |
7 | 7 | thread_summary_page int(8) unsigned NULL, |
8 | | - thread_touched char(14) binary NOT NULL default '', |
| 8 | + thread_timestamp char(14) binary NOT NULL default '', |
| 9 | + thread_revision int(8) unsigned NOT NULL default 1, |
9 | 10 | |
10 | 11 | PRIMARY KEY thread_id (thread_id), |
11 | 12 | UNIQUE INDEX thread_id (thread_id), |
12 | 13 | INDEX( thread_path(255) ), |
13 | | - INDEX thread_touched (thread_touched) |
| 14 | + INDEX thread_timestamp (thread_timestamp) |
14 | 15 | ) TYPE=InnoDB; |
15 | 16 | |
16 | 17 | /* |
Index: branches/liquidthreads/extensions/LqtExtension.php |
— | — | @@ -232,11 +232,10 @@ |
233 | 233 | |
234 | 234 | // For replies and new posts, insert the associated thread object into the DB. |
235 | 235 | if ($edit_type != 'editExisting' && $edit_type != 'summarize' && $e->didSave) { |
236 | | - $thread = Thread::newThread( $article, $this->article ); |
237 | 236 | if ( $edit_type == 'reply' ) { |
238 | | - $thread->setSuperthread( $edit_applies_to ); |
| 237 | + $thread = Threads::newThread( $article, $this->article, $edit_applies_to ); |
239 | 238 | } else { |
240 | | - $thread->touch(); |
| 239 | + $thread = Threads::newThread( $article, $this->article ); |
241 | 240 | } |
242 | 241 | } |
243 | 242 | |
Index: branches/liquidthreads/extensions/LqtModel.php |
— | — | @@ -100,6 +100,12 @@ |
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
| 104 | +class HistoricalThread { |
| 105 | + static function create( $livethread ) { |
| 106 | + echo ("pretended to create new historical thread."); |
| 107 | + } |
| 108 | +} |
| 109 | + |
104 | 110 | class LiveThread { |
105 | 111 | /* ID references to other objects that are loaded on demand: */ |
106 | 112 | protected $rootId; |
— | — | @@ -117,9 +123,31 @@ |
118 | 124 | protected $timestamp; |
119 | 125 | protected $path; |
120 | 126 | |
121 | | - /* Identity */ |
122 | 127 | protected $id; |
| 128 | + protected $revisionNumber; |
| 129 | + |
| 130 | + /* Copy of $this made when first loaded from database, to store the data |
| 131 | + we will write to the history if a new revision is commited. */ |
| 132 | + protected $double; |
| 133 | + |
| 134 | + function commitRevision() { |
| 135 | + // TODO open a transaction. |
| 136 | + HistoricalThread::create( $this->double ); |
123 | 137 | |
| 138 | + $this->revisionNumber += 1; |
| 139 | + |
| 140 | + $dbr =& wfGetDB( DB_MASTER ); |
| 141 | + $res = $dbr->update( 'thread', |
| 142 | + /* SET */array( 'thread_root' => $this->rootId, |
| 143 | + 'thread_article' => $this->articleId, |
| 144 | + 'thread_path' => $this->path, |
| 145 | + 'thread_summary_page' => $this->summaryId, |
| 146 | + 'thread_timestamp' => $this->timestamp, |
| 147 | + 'thread_revision' => $this->revisionNumber ), |
| 148 | + /* WHERE */ array( 'thread_id' => $this->id, ), |
| 149 | + __METHOD__); |
| 150 | + } |
| 151 | + |
124 | 152 | function __construct($line, $children) { |
125 | 153 | $this->id = $line->thread_id; |
126 | 154 | $this->rootId = $line->thread_root; |
— | — | @@ -127,11 +155,13 @@ |
128 | 156 | $this->summaryId = $line->thread_summary_page; |
129 | 157 | $this->path = $line->thread_path; |
130 | 158 | $this->timestamp = $line->thread_timestamp; |
| 159 | + $this->revisionNumber = $line->thread_revision; |
131 | 160 | $this->replies = $children; |
| 161 | + //$this->double = clone $this; |
132 | 162 | } |
133 | 163 | |
134 | 164 | function setSuperthread($thread) { |
135 | | - var_dump("warning setSuperthread unimplemented"); |
| 165 | + $this->path = $thread->path . '.' . $this->id; |
136 | 166 | } |
137 | 167 | |
138 | 168 | function superthread() { |
— | — | @@ -173,6 +203,10 @@ |
174 | 204 | function id() { |
175 | 205 | return $this->id; |
176 | 206 | } |
| 207 | + |
| 208 | + function path() { |
| 209 | + return $this->path; |
| 210 | + } |
177 | 211 | |
178 | 212 | function root() { |
179 | 213 | if ( !$this->rootId ) return null; |
— | — | @@ -187,8 +221,8 @@ |
188 | 222 | } |
189 | 223 | |
190 | 224 | function setSummary( $post ) { |
| 225 | + $this->summary = null; |
191 | 226 | $this->summaryId = $post->getID(); |
192 | | - $this->updateRecord(); |
193 | 227 | } |
194 | 228 | |
195 | 229 | function wikilink() { |
— | — | @@ -256,6 +290,31 @@ |
257 | 291 | |
258 | 292 | static $loadedLiveThreads = array(); |
259 | 293 | |
| 294 | + static function newThread( $root, $article, $superthread = null ) { |
| 295 | + $dbr =& wfGetDB( DB_MASTER ); |
| 296 | + $res = $dbr->insert('thread', |
| 297 | + array('thread_article' => $article->getID(), |
| 298 | + 'thread_root' => $root->getID(), |
| 299 | + 'thread_timestamp' => wfTimestampNow()), |
| 300 | + __METHOD__); |
| 301 | + |
| 302 | + $newid = $dbr->insertId(); |
| 303 | + |
| 304 | + if( $superthread ) { |
| 305 | + $newpath = $superthread->path() . '.' . $newid; |
| 306 | + } else |
| 307 | + { |
| 308 | + $newpath = $newid; |
| 309 | + } |
| 310 | + $res = $dbr->update( 'thread', |
| 311 | + /* SET */ array( 'thread_path' => $newpath ), |
| 312 | + /* WHERE */ array( 'thread_id' => $newid, ), |
| 313 | + __METHOD__); |
| 314 | + |
| 315 | + // TODO we could avoid a query here. |
| 316 | + return Threads::withId($newid); |
| 317 | + } |
| 318 | + |
260 | 319 | static function where( $where, $options = array(), $extra_tables = array() ) { |
261 | 320 | $dbr =& wfGetDB( DB_SLAVE ); |
262 | 321 | if ( is_array($where) ) $where = $dbr->makeList( $where, LIST_AND ); |
— | — | @@ -269,7 +328,11 @@ |
270 | 329 | } |
271 | 330 | |
272 | 331 | /* Select the client's threads, AND all their children. |
273 | | - The ones the client actually asked for are marked with root_test. */ |
| 332 | + The ones the client actually asked for are marked with root_test. |
| 333 | + In theory we could also grab the page and revision data, to avoid having |
| 334 | + to do an additional query for each page, but Article's prodedure for grabbing |
| 335 | + its own data is complicated and it's just not my problem. Plus parser cache. |
| 336 | + */ |
274 | 337 | |
275 | 338 | $root_test = str_replace( 'thread.', 'children.', $where ); // TODO fragile? |
276 | 339 | |
— | — | @@ -290,7 +353,7 @@ |
291 | 354 | |
292 | 355 | foreach( $lines as $key => $l ) { |
293 | 356 | if( $l->is_root ) { |
294 | | - unset($lines[$key]); |
| 357 | +// unset($lines[$key]); |
295 | 358 | $threads[] = Threads::buildLiveThread( &$lines, $l ); |
296 | 359 | } |
297 | 360 | } |
— | — | @@ -299,11 +362,11 @@ |
300 | 363 | |
301 | 364 | private static function buildLiveThread( $lines, $l ) { |
302 | 365 | $children = array(); |
| 366 | + $l_path = preg_quote($l->thread_path); |
303 | 367 | foreach( $lines as $key => $m ) { |
304 | | - if ( $m->thread_path != $l->thread_path && |
305 | | - strpos( $m->thread_path, $l->thread_path ) === 0 ) { |
| 368 | + if ( preg_match( "/^{$l_path}\.\d+$/", $m->thread_path ) ) { |
306 | 369 | // $m->path begins with $l->path; this is a child. |
307 | | - unset($lines[$key]); |
| 370 | +// unset($lines[$key]); |
308 | 371 | $children[] = Threads::buildLiveThread( &$lines, $m ); |
309 | 372 | } |
310 | 373 | } |