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

Commit

Permalink
Add an 'updated' column to wikis
Browse files Browse the repository at this point in the history
  • Loading branch information
edg2s committed Mar 14, 2022
1 parent 4140bd3 commit a21e181
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
'<td data-label="Wiki" class="wiki"><a href="wikis/' . $wiki . '/w" title="' . $wiki . '">' . substr( $wiki, 0, 10 ) . '</a></td>' .
'<td data-label="Patches" class="patches">' . $patches . '</td>' .
'<td data-label="Linked tasks" class="linkedTasks">' . $linkedTasks . '</td>' .
'<td data-label="Time" class="date">' . date( 'Y-m-d H:i:s', $wikiData[ 'created' ] ) . '</td>' .
'<td data-label="Time" class="date">' . date( 'Y-m-d H:i:s', $wikiData[ 'updated' ] ) . '</td>' .
( $useOAuth ? '<td data-label="Creator">' . ( $creator ? user_link( $creator ) : '?' ) . '</td>' : '' ) .
'</tr>' .
'</table>';
Expand Down
2 changes: 1 addition & 1 deletion editcounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
],
];

$results = $mysqli->query( 'SELECT wiki FROM wikis WHERE !deleted ORDER BY created DESC' );
$results = $mysqli->query( 'SELECT wiki FROM wikis WHERE !deleted ORDER BY updated DESC' );
if ( !$results ) {
die( $mysqli->error );
}
Expand Down
16 changes: 12 additions & 4 deletions includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@ function insert_wiki_data( string $wiki, string $creator, int $created, string $
global $mysqli;
$stmt = $mysqli->prepare( '
INSERT INTO wikis
(wiki, creator, created, branch)
VALUES(?, ?, FROM_UNIXTIME(?), ?)
(wiki, creator, created, updated, branch)
VALUES(?, ?, FROM_UNIXTIME(?), FROM_UNIXTIME(?), ?)
' );
if ( !$stmt ) {
echo $mysqli->error;
}
$stmt->bind_param( 'ssis', $wiki, $creator, $created, $branch );
$stmt->bind_param( 'ssiis', $wiki, $creator, $created, $created, $branch );
$stmt->execute();
$stmt->close();
}

function wiki_update_timestamp( string $wiki ) {
global $mysqli;
$stmt = $mysqli->prepare( 'UPDATE wikis SET updated = NOW() WHERE wiki = ?' );
$stmt->bind_param( 's', $wiki );
$stmt->execute();
$stmt->close();
}
Expand Down Expand Up @@ -77,7 +85,7 @@ function get_wiki_data( string $wiki ): array {
global $mysqli;

$stmt = $mysqli->prepare( '
SELECT wiki, creator, UNIX_TIMESTAMP( created ) created, patches, branch, announcedTasks, timeToCreate, deleted
SELECT wiki, creator, UNIX_TIMESTAMP( created ) created, UNIX_TIMESTAMP( updated ) updated, patches, branch, announcedTasks, timeToCreate, deleted
FROM wikis WHERE wiki = ?
' );
if ( !$stmt ) {
Expand Down
6 changes: 3 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@
$username = $user ? $user->username : null;

$stmt = $mysqli->prepare( '
SELECT wiki, creator, UNIX_TIMESTAMP( created ) created, patches, branch, announcedTasks, timeToCreate, deleted
SELECT wiki, creator, UNIX_TIMESTAMP( updated ) updated, patches, branch, announcedTasks, timeToCreate, deleted
FROM wikis
WHERE !deleted
ORDER BY IF( creator = ?, 1, 0 ) DESC, created DESC
ORDER BY IF( creator = ?, 1, 0 ) DESC, updated DESC
' );
if ( !$stmt ) {
die( $mysqli->error );
Expand Down Expand Up @@ -346,7 +346,7 @@
'</td>' .
'<td data-label="Patches" class="patches">' . $patches . '</td>' .
'<td data-label="Linked tasks" class="linkedTasks">' . $linkedTasks . '</td>' .
'<td data-label="Time" class="date">' . date( 'Y-m-d H:i:s', $wikiData[ 'created' ] ) . '</td>' .
'<td data-label="Time" class="date">' . date( 'Y-m-d H:i:s', $wikiData[ 'updated' ] ) . '</td>' .
( $useOAuth ? '<td data-label="Creator">' . ( $creator ? user_link( $creator ) : '?' ) . '</td>' : '' ) .
( $canAdmin ? '<td data-label="Time to create">' . ( $wikiData['timeToCreate'] ? format_duration( $wikiData['timeToCreate'] ) : '' ) . '</td>' : '' ) .
( count( $actions ) ?
Expand Down
6 changes: 6 additions & 0 deletions sql/patchdemo.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,9 @@ ALTER TABLE `tasks`

ALTER TABLE `wikis`
ADD COLUMN IF NOT EXISTS `branch` VARCHAR(64) NOT NULL AFTER `patches`;

ALTER TABLE `wikis`
ADD COLUMN `updated` DATETIME NOT NULL AFTER `created`,
ADD INDEX `updated` (`updated`);

UPDATE wikis SET updated = created;

0 comments on commit a21e181

Please sign in to comment.