Skip to content
This repository was archived by the owner on Sep 23, 2023. It is now read-only.

Commit be0c9c2

Browse files
committed
Add an 'updated' column to wikis
1 parent d724828 commit be0c9c2

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

delete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
'<td data-label="Wiki" class="wiki"><a href="wikis/' . $wiki . '/w" title="' . $wiki . '">' . substr( $wiki, 0, 10 ) . '</a></td>' .
2929
'<td data-label="Patches" class="patches">' . $patches . '</td>' .
3030
'<td data-label="Linked tasks" class="linkedTasks">' . $linkedTasks . '</td>' .
31-
'<td data-label="Time" class="date">' . date( 'Y-m-d H:i:s', $wikiData[ 'created' ] ) . '</td>' .
31+
'<td data-label="Time" class="date">' . date( 'Y-m-d H:i:s', $wikiData[ 'updated' ] ) . '</td>' .
3232
( $useOAuth ? '<td data-label="Creator">' . ( $creator ? user_link( $creator ) : '?' ) . '</td>' : '' ) .
3333
'</tr>' .
3434
'</table>';

editcounts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
],
4848
];
4949

50-
$results = $mysqli->query( 'SELECT wiki FROM wikis WHERE !deleted ORDER BY created DESC' );
50+
$results = $mysqli->query( 'SELECT wiki FROM wikis WHERE !deleted ORDER BY updated DESC' );
5151
if ( !$results ) {
5252
die( $mysqli->error );
5353
}

includes.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,21 @@ function insert_wiki_data( string $wiki, string $creator, int $created, string $
3636
global $mysqli;
3737
$stmt = $mysqli->prepare( '
3838
INSERT INTO wikis
39-
(wiki, creator, created, branch)
40-
VALUES(?, ?, FROM_UNIXTIME(?), ?)
39+
(wiki, creator, created, updated, branch)
40+
VALUES(?, ?, FROM_UNIXTIME(?), FROM_UNIXTIME(?), ?)
4141
' );
4242
if ( !$stmt ) {
4343
echo $mysqli->error;
4444
}
45-
$stmt->bind_param( 'ssis', $wiki, $creator, $created, $branch );
45+
$stmt->bind_param( 'ssis', $wiki, $creator, $created, $created, $branch );
46+
$stmt->execute();
47+
$stmt->close();
48+
}
49+
50+
function wiki_update_timestamp( string $wiki ) {
51+
global $mysqli;
52+
$stmt = $mysqli->prepare( 'UPDATE wikis SET updated = NOW() WHERE wiki = ?' );
53+
$stmt->bind_param( 's', $wiki );
4654
$stmt->execute();
4755
$stmt->close();
4856
}
@@ -77,7 +85,7 @@ function get_wiki_data( string $wiki ): array {
7785
global $mysqli;
7886

7987
$stmt = $mysqli->prepare( '
80-
SELECT wiki, creator, UNIX_TIMESTAMP( created ) created, patches, branch, announcedTasks, timeToCreate, deleted
88+
SELECT wiki, creator, UNIX_TIMESTAMP( created ) created, UNIX_TIMESTAMP( updated ) updated, patches, branch, announcedTasks, timeToCreate, deleted
8189
FROM wikis WHERE wiki = ?
8290
' );
8391
if ( !$stmt ) {

index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@
281281
$username = $user ? $user->username : null;
282282

283283
$stmt = $mysqli->prepare( '
284-
SELECT wiki, creator, UNIX_TIMESTAMP( created ) created, patches, branch, announcedTasks, timeToCreate, deleted
284+
SELECT wiki, creator, UNIX_TIMESTAMP( updated ) updated, patches, branch, announcedTasks, timeToCreate, deleted
285285
FROM wikis
286286
WHERE !deleted
287-
ORDER BY IF( creator = ?, 1, 0 ) DESC, created DESC
287+
ORDER BY IF( creator = ?, 1, 0 ) DESC, updated DESC
288288
' );
289289
if ( !$stmt ) {
290290
die( $mysqli->error );
@@ -346,7 +346,7 @@
346346
'</td>' .
347347
'<td data-label="Patches" class="patches">' . $patches . '</td>' .
348348
'<td data-label="Linked tasks" class="linkedTasks">' . $linkedTasks . '</td>' .
349-
'<td data-label="Time" class="date">' . date( 'Y-m-d H:i:s', $wikiData[ 'created' ] ) . '</td>' .
349+
'<td data-label="Time" class="date">' . date( 'Y-m-d H:i:s', $wikiData[ 'updated' ] ) . '</td>' .
350350
( $useOAuth ? '<td data-label="Creator">' . ( $creator ? user_link( $creator ) : '?' ) . '</td>' : '' ) .
351351
( $canAdmin ? '<td data-label="Time to create">' . ( $wikiData['timeToCreate'] ? $wikiData['timeToCreate'] . 's' : '' ) . '</td>' : '' ) .
352352
( count( $actions ) ?

sql/patchdemo.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ ALTER TABLE `tasks`
4242

4343
ALTER TABLE `wikis`
4444
ADD COLUMN IF NOT EXISTS `branch` VARCHAR(64) NOT NULL AFTER `patches`;
45+
46+
ALTER TABLE `wikis`
47+
ADD COLUMN `updated` DATETIME NOT NULL AFTER `created`,
48+
ADD INDEX `updated` (`updated`);
49+
50+
UPDATE wikis SET updated = created;

0 commit comments

Comments
 (0)