Skip to content

Commit

Permalink
Update checker 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
crftwrk committed Mar 19, 2024
1 parent d1d9f66 commit d220011
Show file tree
Hide file tree
Showing 48 changed files with 241 additions and 242 deletions.
15 changes: 0 additions & 15 deletions update/.editorconfig

This file was deleted.

1 change: 0 additions & 1 deletion update/.gitattributes

This file was deleted.

40 changes: 0 additions & 40 deletions update/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion update/Puc/v5/PucFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

if ( !class_exists(PucFactory::class, false) ):

class PucFactory extends \YahnisElsts\PluginUpdateChecker\v5p3\PucFactory {
class PucFactory extends \YahnisElsts\PluginUpdateChecker\v5p4\PucFactory {
}

endif;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace YahnisElsts\PluginUpdateChecker\v5p3;
namespace YahnisElsts\PluginUpdateChecker\v5p4;

if ( !class_exists(Autoloader::class, false) ):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3\DebugBar;
namespace YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;

use YahnisElsts\PluginUpdateChecker\v5p3\PucFactory;
use YahnisElsts\PluginUpdateChecker\v5p3\UpdateChecker;
use YahnisElsts\PluginUpdateChecker\v5p4\PucFactory;
use YahnisElsts\PluginUpdateChecker\v5p4\UpdateChecker;

if ( !class_exists(Extension::class, false) ):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3\DebugBar;
namespace YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;

use YahnisElsts\PluginUpdateChecker\v5p3\UpdateChecker;
use YahnisElsts\PluginUpdateChecker\v5p4\UpdateChecker;

if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false) ):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace YahnisElsts\PluginUpdateChecker\v5p3\DebugBar;
namespace YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;

use YahnisElsts\PluginUpdateChecker\v5p3\Plugin\UpdateChecker;
use YahnisElsts\PluginUpdateChecker\v5p4\Plugin\UpdateChecker;

if ( !class_exists(PluginExtension::class, false) ):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3\DebugBar;
namespace YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;

use YahnisElsts\PluginUpdateChecker\v5p3\Plugin\UpdateChecker;
use YahnisElsts\PluginUpdateChecker\v5p4\Plugin\UpdateChecker;

if ( !class_exists(PluginPanel::class, false) ):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace YahnisElsts\PluginUpdateChecker\v5p3\DebugBar;
namespace YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;

use YahnisElsts\PluginUpdateChecker\v5p3\Theme\UpdateChecker;
use YahnisElsts\PluginUpdateChecker\v5p4\Theme\UpdateChecker;

if ( !class_exists(ThemePanel::class, false) ):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3;
namespace YahnisElsts\PluginUpdateChecker\v5p4;

if ( !class_exists(InstalledPackage::class, false) ):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3;
namespace YahnisElsts\PluginUpdateChecker\v5p4;

use LogicException;
use stdClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3;
namespace YahnisElsts\PluginUpdateChecker\v5p4;

if ( !class_exists(OAuthSignature::class, false) ):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3\Plugin;
namespace YahnisElsts\PluginUpdateChecker\v5p4\Plugin;

use YahnisElsts\PluginUpdateChecker\v5p3\InstalledPackage;
use YahnisElsts\PluginUpdateChecker\v5p3\PucFactory;
use YahnisElsts\PluginUpdateChecker\v5p4\InstalledPackage;
use YahnisElsts\PluginUpdateChecker\v5p4\PucFactory;

if ( !class_exists(Package::class, false) ):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3\Plugin;
namespace YahnisElsts\PluginUpdateChecker\v5p4\Plugin;

use YahnisElsts\PluginUpdateChecker\v5p3\Metadata;
use YahnisElsts\PluginUpdateChecker\v5p4\Metadata;

if ( !class_exists(PluginInfo::class, false) ):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3\Plugin;
namespace YahnisElsts\PluginUpdateChecker\v5p4\Plugin;

if ( !class_exists('Ui', false) ):
if ( !class_exists(Ui::class, false) ):
/**
* Additional UI elements for plugins.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3\Plugin;
namespace YahnisElsts\PluginUpdateChecker\v5p4\Plugin;

use YahnisElsts\PluginUpdateChecker\v5p3\Update as BaseUpdate;
use YahnisElsts\PluginUpdateChecker\v5p4\Update as BaseUpdate;

if ( !class_exists(Update::class, false) ):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3\Plugin;
namespace YahnisElsts\PluginUpdateChecker\v5p4\Plugin;

use YahnisElsts\PluginUpdateChecker\v5p3\InstalledPackage;
use YahnisElsts\PluginUpdateChecker\v5p3\UpdateChecker as BaseUpdateChecker;
use YahnisElsts\PluginUpdateChecker\v5p3\Scheduler;
use YahnisElsts\PluginUpdateChecker\v5p3\DebugBar;
use YahnisElsts\PluginUpdateChecker\v5p4\InstalledPackage;
use YahnisElsts\PluginUpdateChecker\v5p4\UpdateChecker as BaseUpdateChecker;
use YahnisElsts\PluginUpdateChecker\v5p4\Scheduler;
use YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;

if ( !class_exists(UpdateChecker::class, false) ):

Expand All @@ -17,7 +17,7 @@
*/
class UpdateChecker extends BaseUpdateChecker {
protected $updateTransient = 'update_plugins';
protected $translationType = 'plugin';
protected $componentType = 'plugin';

public $pluginAbsolutePath = ''; //Full path of the main plugin file.
public $pluginFile = ''; //Plugin filename relative to the plugins directory. Many WP APIs use this to identify plugins.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace YahnisElsts\PluginUpdateChecker\v5p3;
namespace YahnisElsts\PluginUpdateChecker\v5p4;

use YahnisElsts\PluginUpdateChecker\v5p3\Plugin;
use YahnisElsts\PluginUpdateChecker\v5p3\Theme;
use YahnisElsts\PluginUpdateChecker\v5p3\Vcs;
use YahnisElsts\PluginUpdateChecker\v5p4\Plugin;
use YahnisElsts\PluginUpdateChecker\v5p4\Theme;
use YahnisElsts\PluginUpdateChecker\v5p4\Vcs;

if ( !class_exists(PucFactory::class, false) ):

Expand Down Expand Up @@ -147,7 +147,7 @@ public static function buildUpdateChecker($metadataUrl, $fullPath, $slug = '', $
*
* Normalize a filesystem path. Introduced in WP 3.9.
* Copying here allows use of the class on earlier versions.
* This version adapted from WP 4.8.2 (unchanged since 4.5.3)
* This version adapted from WP 4.8.2 (unchanged since 4.5.4)
*
* @param string $path Path to normalize.
* @return string Normalized path.
Expand Down
44 changes: 33 additions & 11 deletions update/Puc/v5p3/Scheduler.php → update/Puc/v5p4/Scheduler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3;
namespace YahnisElsts\PluginUpdateChecker\v5p4;

if ( !class_exists(Scheduler::class, false) ):

Expand Down Expand Up @@ -87,6 +87,7 @@ public function __construct($updateChecker, $checkPeriod, $hourlyHooks = array('
add_action($hook, array($this, 'maybeCheckForUpdates'));
}
//This hook fires after a bulk update is complete.
add_action('upgrader_process_complete', array($this, 'removeHooksIfLibraryGone'), 1, 0);
add_action('upgrader_process_complete', array($this, 'upgraderProcessComplete'), 11, 2);

} else {
Expand All @@ -95,6 +96,22 @@ public function __construct($updateChecker, $checkPeriod, $hourlyHooks = array('
}
}

/**
* Remove all hooks if this version of PUC has been deleted or overwritten.
*
* Callback for the "upgrader_process_complete" action.
*/
public function removeHooksIfLibraryGone() {
//Cancel all further actions if the current version of PUC has been deleted or overwritten
//by a different version during the upgrade. If we try to do anything more in that situation,
//we could trigger a fatal error by trying to autoload a deleted class.
clearstatcache();
if ( !file_exists(__FILE__) ) {
$this->removeHooks();
$this->updateChecker->removeHooks();
}
}

/**
* Runs upon the WP action upgrader_process_complete.
*
Expand All @@ -108,16 +125,6 @@ public function upgraderProcessComplete(
/** @noinspection PhpUnusedParameterInspection */
$upgrader, $upgradeInfo
) {
//Cancel all further actions if the current version of PUC has been deleted or overwritten
//by a different version during the upgrade. If we try to do anything more in that situation,
//we could trigger a fatal error by trying to autoload a deleted class.
clearstatcache();
if ( !file_exists(__FILE__) ) {
$this->removeHooks();
$this->updateChecker->removeHooks();
return;
}

//Sanity check and limitation to relevant types.
if (
!is_array($upgradeInfo) || !isset($upgradeInfo['type'], $upgradeInfo['action'])
Expand Down Expand Up @@ -180,6 +187,21 @@ public function maybeCheckForUpdates() {
$state = $this->updateChecker->getUpdateState();
$shouldCheck = ($state->timeSinceLastCheck() >= $this->getEffectiveCheckPeriod());

if ( $shouldCheck ) {
//Sanity check: Do not proceed if one of the critical classes is missing.
//That can happen - theoretically and extremely rarely - if maybeCheckForUpdates()
//is called before the old version of our plugin has been fully deleted, or
//called from an independent AJAX request during deletion.
if ( !(
class_exists(Utils::class)
&& class_exists(Metadata::class)
&& class_exists(Plugin\Update::class)
&& class_exists(Theme\Update::class)
) ) {
return;
}
}

//Let plugin authors substitute their own algorithm.
$shouldCheck = apply_filters(
$this->updateChecker->getUniqueName('check_now'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3;
namespace YahnisElsts\PluginUpdateChecker\v5p4;

if ( !class_exists(StateStore::class, false) ):

Expand Down Expand Up @@ -163,7 +163,12 @@ protected function load() {

$state = get_site_option($this->optionName, null);

if ( !is_object($state) ) {
if (
!is_object($state)
//Sanity check: If the Utils class is missing, the plugin is probably in the process
//of being deleted (e.g. the old version gets deleted during an update).
|| !class_exists(Utils::class)
) {
$this->lastCheck = 0;
$this->checkedVersion = '';
$this->update = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3\Theme;
namespace YahnisElsts\PluginUpdateChecker\v5p4\Theme;

use YahnisElsts\PluginUpdateChecker\v5p3\InstalledPackage;
use YahnisElsts\PluginUpdateChecker\v5p4\InstalledPackage;

if ( !class_exists(Package::class, false) ):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace YahnisElsts\PluginUpdateChecker\v5p3\Theme;
namespace YahnisElsts\PluginUpdateChecker\v5p4\Theme;

use YahnisElsts\PluginUpdateChecker\v5p3\Update as BaseUpdate;
use YahnisElsts\PluginUpdateChecker\v5p4\Update as BaseUpdate;

if ( !class_exists(Update::class, false) ):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php

namespace YahnisElsts\PluginUpdateChecker\v5p3\Theme;
namespace YahnisElsts\PluginUpdateChecker\v5p4\Theme;

use YahnisElsts\PluginUpdateChecker\v5p3\UpdateChecker as BaseUpdateChecker;
use YahnisElsts\PluginUpdateChecker\v5p3\InstalledPackage;
use YahnisElsts\PluginUpdateChecker\v5p3\Scheduler;
use YahnisElsts\PluginUpdateChecker\v5p3\DebugBar;
use YahnisElsts\PluginUpdateChecker\v5p4\UpdateChecker as BaseUpdateChecker;
use YahnisElsts\PluginUpdateChecker\v5p4\InstalledPackage;
use YahnisElsts\PluginUpdateChecker\v5p4\Scheduler;
use YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;

if ( !class_exists(UpdateChecker::class, false) ):

class UpdateChecker extends BaseUpdateChecker {
protected $filterSuffix = 'theme';
protected $updateTransient = 'update_themes';
protected $translationType = 'theme';
protected $componentType = 'theme';

/**
* @var string Theme directory name.
Expand Down
2 changes: 1 addition & 1 deletion update/Puc/v5p3/Update.php → update/Puc/v5p4/Update.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace YahnisElsts\PluginUpdateChecker\v5p3;
namespace YahnisElsts\PluginUpdateChecker\v5p4;

use stdClass;

Expand Down
Loading

0 comments on commit d220011

Please sign in to comment.