Skip to content

Commit

Permalink
Fixed Update
Browse files Browse the repository at this point in the history
  • Loading branch information
makhonkodenis committed Jun 18, 2015
1 parent bade5ee commit 1bd2ac5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
27 changes: 11 additions & 16 deletions admin/includes/class-cherry-update/class-cherry-base-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ class Cherry_Base_Update {
);

protected function base_init( $attr = array() ){
$this ->api = array_merge( $this ->api, $attr );

add_filter( 'upgrader_source_selection', array( $this, 'rename_github_folder' ), 11, 3 );
$this->api = array_merge( $this->api, $attr );
}

protected function check_update() {
$query = $this -> api[ 'api_url' ] . $this -> api[ 'product_name' ] . '/' . $this -> api[ 'repository_name' ] . '/tags';
$query = $this->api[ 'api_url' ] . $this->api[ 'product_name' ] . '/' . $this->api[ 'repository_name' ] . '/tags';
$response = $this -> remote_query( $query );
$new_version = false;
$url = '';
Expand All @@ -53,28 +51,28 @@ protected function check_update() {

$response = array_reverse( $response );
$last_update = count( $response )-1;
$current_version = $this -> api[ 'version' ];
$current_version = $this->api[ 'version' ];

foreach ($response as $key => $update) {

$get_new_version = strtolower( $update->name );
$update_label = preg_replace( '/[v]?[\d\.]+[v]?/', '', $get_new_version );
$get_new_version = preg_replace( '/[^\d\.]/', '', $get_new_version );

$this -> api[ 'details_url' ] = 'https://github.com/' . $this -> api[ 'product_name' ] . '/' . $this -> api[ 'slug' ] . '/releases/tag/' . $update->name;
$this->api[ 'details_url' ] = 'https://github.com/' . $this->api[ 'product_name' ] . '/' . $this->api[ 'slug' ] . '/releases/tag/' . $update->name;
$package = $update->zipball_url;

if( version_compare ( $get_new_version, $current_version ) > 0 && strpos( $update_label, $this -> api[ 'important_release' ] ) !== false ){
if( version_compare ( $get_new_version, $current_version ) > 0 && strpos( $update_label, $this->api[ 'important_release' ] ) !== false ){

$new_version = $get_new_version;
break;
}

if( version_compare ( $get_new_version, $current_version ) > 0 && $key === $last_update ){

if($update_label !== $this -> api[ 'alpha_release' ] && $update_label !== $this -> api[ 'beta_release' ]
|| $update_label === $this -> api[ 'alpha_release' ] && @constant ( 'CHERRY_ALPHA_UPDATE' ) == true
|| $update_label === $this -> api[ 'beta_release' ] && @constant ( 'CHERRY_BETA_UPDATE' ) == true ){
if($update_label !== $this->api[ 'alpha_release' ] && $update_label !== $this->api[ 'beta_release' ]
|| $update_label === $this->api[ 'alpha_release' ] && @constant ( 'CHERRY_ALPHA_UPDATE' ) == true
|| $update_label === $this->api[ 'beta_release' ] && @constant ( 'CHERRY_BETA_UPDATE' ) == true ){

$new_version = $get_new_version;

Expand All @@ -88,7 +86,7 @@ protected function check_update() {
}

protected function remote_query( $query ) {
$response = wp_remote_get( $query , array( 'sslverify' => $this -> api[ 'sslverify' ] , 'user-agent' => $this -> api[ 'product_name' ] ) );
$response = wp_remote_get( $query , array( 'sslverify' => $this->api[ 'sslverify' ] , 'user-agent' => $this->api[ 'product_name' ] ) );

if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != '200') {
return false;
Expand All @@ -100,12 +98,9 @@ protected function remote_query( $query ) {
}

public function rename_github_folder( $upgrate_dir, $remote_dir, $skin_upgrader ){
$skin_theme = isset($skin_upgrader ->skin ->theme) ? $skin_upgrader ->skin ->theme : '' ;
$skin_plugin = isset($skin_upgrader ->skin ->plugin) ? $skin_upgrader ->skin ->plugin : '' ;

if( $skin_theme === $this -> api[ 'slug' ] || $skin_plugin === $this -> api[ 'slug' ] ){
if( strpos( $upgrate_dir, $this->api[ 'slug' ] ) !== false){
$upgrate_dir_path = pathinfo( $upgrate_dir );
$new_upgrate_dir = trailingslashit( $upgrate_dir_path[ 'dirname' ] ) . trailingslashit( $this -> api[ 'slug' ] );
$new_upgrate_dir = trailingslashit( $upgrate_dir_path[ 'dirname' ] ) . trailingslashit( $this->api[ 'slug' ] );

rename( $upgrate_dir, $new_upgrate_dir );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function init( $attr = array() ){
//set_site_transient('update_plugins', null);

add_action( 'pre_set_site_transient_update_plugins', array( $this, 'update' ) );
add_filter( 'upgrader_source_selection', array( $this, 'rename_github_folder' ), 11, 3 );
add_action( 'admin_footer', array( $this, 'change_details_url' ) );
}
}
Expand All @@ -36,17 +37,18 @@ public function update( $data ) {
$new_update = $this -> check_update();

if( $new_update[ 'version' ] ){
$this -> api[ 'plugin' ] = $this -> api[ 'slug' ] . '/' . $this -> api[ 'slug' ] . '.php';
$this->api[ 'plugin' ] = $this->api[ 'slug' ] . '/' . $this->api[ 'slug' ] . '.php';

$update = new stdClass();

$update -> slug = $this -> api[ 'slug' ];
$update -> plugin = $this -> api[ 'plugin' ];
$update -> slug = $this->api[ 'slug' ];
$update -> plugin = $this->api[ 'plugin' ];
$update -> new_version = $new_update[ 'version' ];
$update -> url = $this -> api[ 'details_url' ];
$update -> url = $this->api[ 'details_url' ];
$update -> package = $new_update[ 'package' ];

$data -> response[ $this -> api[ 'plugin' ] ] = $update;
$data -> response[ $this->api[ 'plugin' ] ] = $update;

}

return $data;
Expand Down

0 comments on commit 1bd2ac5

Please sign in to comment.