Skip to content

Commit

Permalink
record the wup-client version, closes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcath committed Feb 11, 2019
1 parent 6938f32 commit 73ef404
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
13 changes: 12 additions & 1 deletion lib/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public function returnJson(){
return;
}

if(isset($headers['WUP_CLIENT_VERSION'])){
$wup_client_version = $headers['WUP_CLIENT_VERSION'];
}else{
$wup_client_version = "< 0.1.2";
}

$package = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}wup_packages WHERE `slug` = '{$slug}'", 'ARRAY_A');

if($package == null){
Expand All @@ -53,7 +59,6 @@ public function returnJson(){
return;
}


$version = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}wup_versions WHERE `packageId` = '{$package['id']}' ORDER BY `id` DESC LIMIT 1", 'ARRAY_A');

if($version == null){
Expand All @@ -80,6 +85,12 @@ public function returnJson(){

$wpdb->query($sql);

if($headers['WP_VERSION'] === $version['version']){
// This site is already running the latest.
$sql = "UPDATE {$wpdb->prefix}wup_packages SET `wup_client_version` = '{$wup_client_version}' WHERE `id` = '{$package['id']}'";
$wpdb->query($sql);
}

wp_send_json(array(
'slug' => $slug,
'name' => $data['header']['Name'],
Expand Down
15 changes: 14 additions & 1 deletion lib/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,20 @@ function wup_run_migration(){
) ENGINE = InnoDB;',
'post' => '0.0.4'
),
'0.0.4' => false
'0.0.4' => array(
'migration' => 'CREATE TABLE ' . $wpdb->prefix . 'wup_packages (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(255) NOT NULL ,
`slug` VARCHAR(255) NOT NULL ,
`deployKey` VARCHAR(64) NOT NULL ,
`wup_client_version` VARCHAR(10) NOT NULL DEFAULT "0.0.0" ,
PRIMARY KEY (`id`),
UNIQUE (`slug`),
UNIQUE (`deployKey`)
) ENGINE = InnoDB;',
'post' => '0.0.5'
),
'0.0.5' => false
);

$currentVersion = get_site_option('wup_db_version');
Expand Down
3 changes: 3 additions & 0 deletions lib/pages/view-package.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
Version Number: <?php echo($version['version']); ?><br ?>
<a href="<?php echo(content_url('uploads/wup-releases/' . $package['slug'] . '/' . $version['version'] . '.zip')); ?>">Download latest ZIP</a>
</p>
<p>
WUP-Client version: <?php echo($package['wup_client_version']); ?>
</p>
<h3>Deploy Key</h3>
<p><?php echo($package['deployKey']); ?></p>
<p><a href="?page=wup_package&package=<?php echo($package['slug']); ?>&action=newKey">Regenerate Key</a></p>
Expand Down
4 changes: 3 additions & 1 deletion lib/tables/packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function column_default($item, $column_name){
switch($column_name){
case 'slug':
case 'deployKey':
case 'wup_client_version':
return $item[$column_name];
default:
return print_r($item, true);
Expand All @@ -83,7 +84,8 @@ function get_columns(){
'slug' => __('Slug', 'wp-update-provider'),
'versions' => __('Versions', 'wp-update-provider'),
'deployKey' => __('Deploy Key', 'wp-update-provider'),
'installs' => __('Installs', 'wp-update-provider')
'installs' => __('Installs', 'wp-update-provider'),
'wup_client_version' => __('WUP Client Version', 'wp-update-provider')
];

return $columns;
Expand Down

0 comments on commit 73ef404

Please sign in to comment.