Commit Graph

229 Commits

Author SHA1 Message Date
Yahnis Elsts 579d537926 Add a PHPCS configuration and fix or silence all current warnings/errors
The main functional change is that PUC will now use shorter HTTP request timeouts when not running inside a Cron task. This is to comply with the WP VIP coding standard that strongly recommends a maximum timeout of 3 seconds.

Prompted by #107
2023-05-01 12:28:55 +03:00
Yahnis Elsts ebf5bc21a0 Revert accidentally committed TODO
This reverts commit 573467a543.
2023-03-08 19:29:08 +02:00
Yahnis Elsts 573467a543 Use the same KO component for CheckBox and the toggle checkbox. 2023-03-08 19:23:53 +02:00
Yahnis Elsts c86ce6ef9f Better check to see if the update creation method exists.
Based on a user report, there are cases where just checking if the *class* exists is not sufficient.
2023-01-17 21:15:38 +02:00
Franky Van Liedekerke 75c05617ec
Also allow "main" as branch for github assets
When setting
$myUpdateChecker->setBranch('main');
the setting enableReleaseAssets was ignored. But since on newer versions "main" is the default (and not "master"), it should allow it.
2023-01-01 22:34:49 +01:00
Franky Van Liedekerke 2fb701089d
Fix GitHub assets
array_filter keeps the index, so if the asset matching has index 1, an array with key 1 is returned. However, further down, $matchingAssets[0] is always used. This will then fail. Using array_values after array_filter resets the indexes on the array from 0, solving the problem.
2023-01-01 22:26:25 +01:00
Yahnis Elsts 304020175d Minor: Fix grammar mistake in an error message 2022-12-01 17:38:30 +02:00
Yahnis Elsts c4bf64eca4 Add a way to filter GitHub and Gitlab releases.
The filter is applied when trying to get the latest release from a VCS repository. Inspired by #506.

Example of filtering releases by the version number: 
```php
//Allow only beta versions (e.g. for testing).
$updateChecker->getVcsApi()->setReleaseVersionFilter(
    '/beta/i', //Regex for the version number.
    Api::RELEASE_FILTER_ALL, //Disables the default filter(s).
    30 //Max number of recent releases to scan for matches.
);
```

Alternatively, you can use a callback to implement custom filtering rules. 
```php
//Set an arbitrary custom filter.
$updateChecker->getVcsApi()->setReleaseFilter(
    function($versionNumber, $releaseObject) {
        /* 
        Put your custom logic here. The $releaseObject variable contains
        the release data returned by the GitHub/GitLab API. The format
        will vary depending on which service you're using.
        */
        return true;
    },
    Api::RELEASE_FILTER_ALL
);
```

Setting a new filter will override any previous filters, so you can't add a regex-based version filter and a custom callback at the same time.
2022-11-17 18:26:23 +02:00
Yahnis Elsts affb44665f Refactor release asset support.
The GitLab release asset implementation was unnecessarily complex and did not match the coding style of the rest of the project (it was provided by an external contributor, and I didn't feel like rewriting it at the time). With the recent change of requiring PHP 5.6 as the minimum version, it's now possible to extract most of the asset logic into a new trait.

This also provided the opportunity to add an undocumented way to *require* that a release have assets:
`enableReleaseAssets('optional-regex', Vcs\Api::REQUIRE_RELEASE_ASSETS)`  

Prompted by #505
2022-11-08 18:29:37 +02:00
Yahnis Elsts 81be284da7 Fix inconsistent directory separators in the autoloader.
It looks like this was the cause of a version 5.0 bug reported in #378.
2022-10-28 20:46:32 +03:00
Yahnis Elsts 32f0079038 Minor: Fix incorrect class name in a doc comment 2022-10-28 14:01:49 +03:00
Yahnis Elsts b85b82f82d Fixed deprecation notice related to htmlentities.
The notice: "Passing null to parameter #1 ($string) of type string is deprecated". This could be triggered because some update fields can be null, like the upgrade notice field.
2022-10-15 20:58:18 +03:00
Yahnis Elsts a680a49789 Replace old class name with namespaced class name.
Also, we don't need the explicit "use" statement in this file because relative names work fine.
2022-10-15 00:27:46 +03:00
Yahnis Elsts 749f33c5c4 Fixed many WPCS warnings
This fixes or explicitly ignores most - but not all - coding standard issues that are reported when running PHP_CodeSniffer with the basic WordPress ruleset and the WordPress-VIP ruleset. 

Notably, one of the issues that remain is the request timeout for update requests and VCS API requests. The current default is 10 seconds, but the WordPress-VIP standards appear to require 3 seconds or less. Personally, I'm not sure if that low limit is appropriate for requests that are intended to mostly run in Cron jobs.
2022-10-14 19:37:00 +03:00
Yahnis Elsts 6c9fce0887 Minor: Remove unnecessary PHP version check.
PHP 5.6 is now the minimum supported version.
2022-10-13 20:12:41 +03:00
Yahnis Elsts 44baf224b8 When saving cached updates, set the library prefix to just the namespace.
This means that previously cached updates can't be loaded by this version, but that should be fine. The cache will just get updated the next time PUC checks for updates.
2022-10-13 20:07:00 +03:00
Yahnis Elsts bec5c00e89 Minor: Remove obsolete code that was originally added for PHP 5.3 compatibility 2022-10-13 17:50:14 +03:00
Yahnis Elsts 0784d3fff2 Fix non-napespaced class name in requestInfo 2022-10-13 17:49:29 +03:00
Yahnis Elsts ac3c24029c Fix own version detection 2022-10-13 17:48:49 +03:00
Yahnis Elsts d86f4f4b94 Minor: Remove some unreachable code.
trigger_error() should stop execution when the error type is E_USER_ERROR.
2022-10-09 18:52:41 +03:00
Yahnis Elsts 2b97a8f712 Extract common VCS update checker stuff into a new to reduce code duplication. 2022-10-09 18:46:36 +03:00
Yahnis Elsts 2dbb2baff1 Bump the version number in Debug Bar HTML.
Technically, this is not necessary because that part of the library hasn't really changed, but let's use the same version number everywhere for consistency.
2022-10-09 00:58:18 +03:00
Yahnis Elsts 4b6127f0f2 Put all^ PUC classes in namespaces.
^ Except dependencies like Parsedown.

The readme is now out of date. The legacy version of Parsedown was removed because we no longer need to support PHP versions older than 5.3. The stub file that loads ParsedownModern.php stays in place because it has the "class_exists" check.
2022-10-08 23:15:37 +03:00
Yahnis Elsts 0d4d717cde Bump version number to 5.0 2022-10-08 20:07:42 +03:00
Yahnis Elsts 8a82397a6e Minor: Remove some redundant IDE notice suppressions. 2022-09-06 15:14:17 +03:00
Yahnis Elsts adbfa5dd3a Add a way to filter VCS update detection strategies
Example: 
```
$bitbucketPluginChecker->addFilter('vcs_update_detection_strategies', function($strategies) {
 	//Don't look for a "Stable tag" header in readme.txt.
 	unset($strategies['stable_tag']);
 	return $strategies;
});
```

To make this possible, the chooseReference() method was refactored into something that more closely resembles a "chain of responsibility" pattern. Instead of a tree of "if" conditions, it now gets an array of callables from another method, and it calls each of those in order until it gets a non-empty VCS reference.

You can filter this array to remove specific strategies, or even to add your own. Note that the item order matters.

Required PHP version was increased to 5.4 because some "strategies" take an argument and some don't, and I would rather just use closures for that than something more complex.

Coincidentally, testing this change revealed a bug where the HTTP filter name was not initialized correctly: it was missing the $slug. That should also be fixed now. 

Prompted by #378
2022-09-06 15:13:15 +03:00
Yahnis Elsts 5b863c26bd Fix a potential PHP notice when detecting a VCS service
In the (unlikely) case where the update metadata URL does not include a path, the getVcsService() method could previously trigger a deprecation notice like "preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated". This is because parse_url() returns NULL when the specified component is not present.

Fixed by always casting the $path to string. The VCS detection code doesn't care about the difference between "empty path" and "no path" - it should correctly return NULL (= no VCS host found) anyway.

Also, let's cast $host to a string as well to avoid another potential notice if the URL somehow has a path but no domain name.

Initially reported in #499.
2022-08-06 17:29:44 +03:00
Yahnis Elsts 6eb27a6911 Bump version to 4.13
Also updated the POT file. No new strings, but some of the source code references were out of date.
2022-07-29 15:36:25 +03:00
Yahnis Elsts 3347254e0d Fail-safe when update class cannot be correctly reconstructed or loaded.
Previously, if the wrong base class name was written to the database, attempts to load update information could trigger a warning because there was no class_exists() check in the "updateBaseClass is set" branch. To fix that, I've moved the class_exists() closer to the place where the class name is actually used.

StateStore will still fail to load a stored update if the class name is invalid, but without a PHP warning this time. The invalid stored update information should be overwritten the next time PUC checks for updates.
2022-07-28 16:01:14 +03:00
Yahnis Elsts b4c5a82cc8 Fix (hopefully) a warning when loading update details stored by a different version of PUC that was also using a custom namespace.
Reported in #498.
2022-07-28 14:57:21 +03:00
Yahnis Elsts ae5789b5a7 Rename classes for 4.12 2022-07-25 00:33:05 +03:00
Yahnis Elsts 568e845d89 Begin 4.12 version change
Rename versioned directory
2022-07-25 00:24:42 +03:00
Yahnis Elsts f478379ed7 Replace defined('__NAMESPACE__') conditions with PHP version checks. 2022-07-21 12:28:39 +03:00
Yahnis Elsts 3119408761 Attempt to fix some PHP Scoper compatibility issues. See #496 2022-07-14 17:54:22 +03:00
Yahnis Elsts a68681e54b Minor: Add a TODO for the GitLab integration.
I haven't gotten around to completing it, but don't want to dismiss it either.
2022-04-15 13:24:25 +03:00
Yahnis Elsts 0e869938e3 Refactoring: Extract asset detection to a method.
This applies to locally stored plugin icons and banners. The code for icons and banners was very similar, so I've turned it into a utility method to reduce code duplication.
2021-10-01 14:55:59 +03:00
Tim Wiel e5453b52e4 Use plugin icons from the local "assets" directory. 2021-09-29 14:24:36 +13:00
Yahnis Elsts 8a8788d965 Use plugin icons from the local "assets" directory.
Props to @timwiel for the suggestion and the original implementation. See  #461. 

This change applies to plugins (but not themes) that are updated from a VCS hosting provider like GitHub. Previously, the plugin author would have had to use a filter to provide icons. Now they can just put them in a subdirectory named "assets" instead. Icon file names and extensions should match those described here:
https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#plugin-icons

Note that the update checker will use icons from the installed version, not from the VCS repository.
2021-09-27 20:25:50 +03:00
Yahnis Elsts a5dd2bb951 Make "enableReleasePackages" plural so that it's consistent with "enableReleaseAssets" 2021-09-23 18:11:12 +03:00
Tim Wiel cea29dcaaa Fixed authentication issues for public repos and re-priortised the order of update checking from Gitlab to match the Github methodology 2021-09-23 13:48:02 +12:00
Tim Wiel 57ceef7685 Minor comment change to better reflect code functionality 2021-09-22 16:25:15 +12:00
Tim Wiel 91d089876f Ordering the priority of version checks for Gitlab and updating README.md accordingly 2021-09-22 14:41:02 +12:00
Tim Wiel e16a46fc72 Filtering out "upcoming releases" from the releases available to PUC 2021-09-22 12:53:01 +12:00
Tim Wiel 824348c036 Adding checks for the assets to ensure they are zip files which is what wordpress needs to update 2021-09-22 12:11:37 +12:00
Tim Wiel cb44a6ede1 Adding releases to GitLab API with option for release asset download from either: source OR generic package releases (see https://gitlab.com/gitlab-org/release-cli/-/tree/master/docs/examples/release-assets-as-generic-package/) 2021-09-21 13:48:25 +12:00
Geoff Thibeau 048b78cdd5
Adds possible default branch name 'main': Bitbucket
Adds `main` as a possible default branch name to invoke `$this->getLatestTag()` inside of `Puc_v4p11_Vcs_BitBucketApi::chooseReference()`.

Previously, only branches named `master` inherited this special behavior. With more VCS providers opting for an inclusive default branch name, this commit adds `main` as a default branch name configuration.

Related to #422.
2021-05-18 18:49:36 -05:00
Yahnis Elsts e5384a52c7 Merge branch 'master' into wp55-auto-updates 2021-05-12 21:30:14 +03:00
Yahnis Elsts 3155f2d3f1 Change version number in file/directory names
Step 2 of version bump
2021-03-15 18:07:52 +02:00
Yahnis Elsts 06bc75f9af Change version infix from v4p10 to v4p11
Step 1 of version bump
2021-03-15 18:02:04 +02:00
Marco Rocca 8a1a779f00 Fixed wrong call to inexistent property 2021-03-12 00:10:50 +01:00