Skip to content

Commit

Permalink
Merge pull request #11 from Ed-ITSolutions/0.1.8
Browse files Browse the repository at this point in the history
WIP 0.1.8
  • Loading branch information
Arcath authored Feb 11, 2019
2 parents 36aa2f6 + 72bcf6a commit a4766ce
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 9 deletions.
21 changes: 17 additions & 4 deletions 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 @@ -73,13 +78,19 @@ public function returnJson(){
if($domain == null){
$sql = "INSERT INTO {$wpdb->prefix}wup_domains (`packageId`, `domain`, `version`) VALUES ('{$package['id']}', '{$headers['WP_DOMAIN']}', '{$headers['WP_VERSION']}')";
}else{
$sql = "UPDATE {$wpdb->prefix}wup_domains SET `version` = '{$headers['WP_VERSION']}' WHERE `id` = '{$domain['id']}' ";
$sql = "UPDATE {$wpdb->prefix}wup_domains SET `version` = '{$headers['WP_VERSION']}', `lastCheckIn` = CURRENT_TIMESTAMP WHERE `id` = '{$domain['id']}' ";
}

$this->log('Request for ' . $slug . ' from ' . $headers['WP_DOMAIN'] . ' @ ' . $headers['WP_VERSION'] . '.');

$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 Expand Up @@ -169,15 +180,15 @@ private function addPackage($package){
public function viewPackagePage(){
global $wpdb;

if($_GET['action'] == 'newKey'){
if(array_key_exists('action', $_GET) && $_GET['action'] == 'newKey'){
$deployKey = wp_create_nonce('deploy-' . $_GET['package'] . time());

$sql = "UPDATE {$wpdb->prefix}wup_packages SET `deployKey` = '{$deployKey}' WHERE `slug` = '{$_GET['package']}'";

$wpdb->query($sql);
}

if($_GET['action'] == 'delete'){
if(array_key_exists('action', $_GET) && $_GET['action'] == 'delete'){
$nonce = esc_attr($_REQUEST['_wpnonce']);

if(!wp_verify_nonce($nonce, 'wup_delete_domain')){
Expand Down Expand Up @@ -274,6 +285,8 @@ public function newRelease(){
wp_upload_dir()['basedir'] . '/wup-releases/' . $package['slug'] . '/' . $meta['header']['Version'] . '.zip'
);

copy(wp_upload_dir()['basedir'] . '/wup-releases/' . $package['slug'] . '/' . $meta['header']['Version'] . '.zip', wp_upload_dir()['basedir'] . '/wup-releases/' . $package['slug'] . '/latest.zip');

$pluginData = serialize($meta);

$sql = "INSERT INTO {$wpdb->prefix}wup_versions (`packageId`, `version`, `releaseDate`, `pluginData`) VALUES ('{$package['id']}', '{$meta['header']['Version']}', NOW(), '{$pluginData}')";
Expand Down
26 changes: 25 additions & 1 deletion lib/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,31 @@ 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' => array(
'migration' => 'CREATE TABLE ' . $wpdb->prefix . 'wup_domains (
`id` INT NOT NULL AUTO_INCREMENT ,
`packageId` INT NOT NULL ,
`domain` VARCHAR(255) NOT NULL ,
`version` VARCHAR(10) NOT NULL ,
`lastCheckIn` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY (`id`)
) ENGINE = InnoDB;',
'post' => '0.0.6'
),
'0.0.6' => false
);

$currentVersion = get_site_option('wup_db_version');
Expand Down
11 changes: 10 additions & 1 deletion lib/pages/view-package.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
wp_upload_dir()['basedir'] . '/wup-releases/' . $package['slug'] . '/' . $meta['header']['Version'] . '.zip'
);

copy(wp_upload_dir()['basedir'] . '/wup-releases/' . $package['slug'] . '/' . $meta['header']['Version'] . '.zip', wp_upload_dir()['basedir'] . '/wup-releases/' . $package['slug'] . '/latest.zip');

$pluginData = serialize($meta);

$sql = "INSERT INTO {$wpdb->prefix}wup_versions (`packageId`, `version`, `releaseDate`, `pluginData`) VALUES ('{$package['id']}', '{$meta['header']['Version']}', NOW(), '{$pluginData}')";
Expand All @@ -38,7 +40,14 @@
<h3>Current Version</h3>
<p>
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>
<?php if(file_exists(wp_upload_dir()['basedir'] . '/wup-releases/' . $package['slug'] . '/latest.zip')){ ?>
<a href="<?php echo(content_url('uploads/wup-releases/' . $package['slug'] . '/latest.zip')); ?>">Download latest ZIP</a>
<?php }else{ ?>
<a href="<?php echo(content_url('uploads/wup-releases/' . $package['slug'] . '/' . $version['version'] . '.zip')); ?>">Download latest ZIP</a>
<?php } ?>
</p>
<p>
WUP-Client version: <?php echo($package['wup_client_version']); ?>
</p>
<h3>Deploy Key</h3>
<p><?php echo($package['deployKey']); ?></p>
Expand Down
4 changes: 3 additions & 1 deletion lib/tables/domains.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function column_default($item, $column_name){
switch($column_name){
case 'domain':
case 'version':
case 'lastCheckIn':
return $item[$column_name];
default:
return print_r($item, true);
Expand All @@ -76,7 +77,8 @@ function column_default($item, $column_name){
function get_columns(){
$columns = [
'domain' => __('Domain', 'wp-update-provider'),
'version' => __('Version', 'wp-update-provider')
'version' => __('Version', 'wp-update-provider'),
'lastCheckIn' => __('Last Check In', 'wp-update-provider')
];

return $columns;
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
2 changes: 1 addition & 1 deletion wp-update-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: WP Update Provider
* Description: Provides an update server for WordPress plugins & themes, and manages sites that are updating.
* Version: 0.1.7
* Version: 0.1.8
* Author: Ed-IT Solutions
* Author URI: http://www.ed-itsolutions.com
* Image: https://raw.githubusercontent.com/Ed-ITSolutions/wp-update-provider/master/docs/logo.png
Expand Down

0 comments on commit a4766ce

Please sign in to comment.