Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
afragen committed Sep 2, 2022
2 parents 6869620 + e117e8c commit f956441
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 66 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#### [unreleased]

#### 11.1.0 / 2022-09-02
* add `str_contains`, `str_starts_with`, `str_ends_with` polyfills
* decrease WP requirement back to 5.2
* update `Shim` for improved function
* load `Shim` in autoloader

#### 11.0.6 / 2022-08-31
* fix `rename_on_activation` with `move_dir`

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
"autoload": {
"psr-4": {
"Fragen\\Git_Updater\\": "src/Git_Updater/"
}
},
"files": [
"src/Git_Updater/Shim.php"
]
},
"scripts": {
"post-update-cmd": [
Expand Down
4 changes: 2 additions & 2 deletions git-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
* Plugin Name: Git Updater
* Plugin URI: https://git-updater.com
* Description: A plugin to automatically update GitHub hosted plugins, themes, and language packs. Additional API plugins available for Bitbucket, GitLab, Gitea, and Gist.
* Version: 11.0.6
* Version: 11.1.0
* Author: Andy Fragen
* License: MIT
* Domain Path: /languages
* Text Domain: git-updater
* Network: true
* GitHub Plugin URI: https://github.com/afragen/git-updater
* GitHub Languages: https://github.com/afragen/git-updater-translations
* Requires at least: 5.9
* Requires at least: 5.2
* Requires PHP: 7.2
*/

Expand Down
6 changes: 1 addition & 5 deletions src/Git_Updater/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,7 @@ public function upgrader_source_selection( $source, $remote_source, $upgrader, $
$new_source = $this->fix_misnamed_directory( $new_source, $remote_source, $upgrader_object, $slug );

if ( $source !== $new_source ) {
if ( function_exists( 'move_dir' ) ) {
$result = \move_dir( $source, $new_source );
} else {
$result = move_dir( $source, $new_source );
}
$result = move_dir( $source, $new_source );
if ( \is_wp_error( $result ) ) {
return $result;
}
Expand Down
10 changes: 2 additions & 8 deletions src/Git_Updater/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public function run() {

register_deactivation_hook( $this->file, [ $this, 'remove_cron_events' ] );

require_once __DIR__ . '/Shim.php';
( new Init() )->run();

// Initialize time dissmissible admin notices.
Expand Down Expand Up @@ -146,7 +145,7 @@ public function remove_cron_events() {
*
* `rename()` causes activation to fail.
*
* @return void
* @return void|bool
*/
public function rename_on_activation() {
$plugin_dir = trailingslashit( WP_PLUGIN_DIR );
Expand All @@ -159,13 +158,8 @@ public function rename_on_activation() {
update_site_option( 'git_updater', array_merge( $options, [ 'current_branch_git-updater' => 'develop' ] ) );
}

require_once __DIR__ . '/Shim.php';
if ( $slug && 'git-updater/git-updater.php' !== $slug ) {
if ( function_exists( 'move_dir' ) ) {
$result = \move_dir( $plugin_dir . dirname( $slug ), $plugin_dir . 'git-updater' );
} else {
$result = move_dir( $plugin_dir . dirname( $slug ), $plugin_dir . 'git-updater' );
}
$result = move_dir( $plugin_dir . dirname( $slug ), $plugin_dir . 'git-updater' );
if ( \is_wp_error( $result ) ) {
return $result;
}
Expand Down
156 changes: 110 additions & 46 deletions src/Git_Updater/Shim.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,134 @@
* @package git-updater
*/

/**
* Loads WP 6.1 modified functions from Rollback.
*/

namespace Fragen\Git_Updater;

/**
* Moves a directory from one location to another via the rename() PHP function.
* If the renaming failed, falls back to copy_dir().
*
* Assumes that WP_Filesystem() has already been called and setup.
*
* @since 6.1.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param string $from Source directory.
* @param string $to Destination directory.
* @return true|WP_Error True on success, WP_Error on failure.
/*
* Exit if called directly.
*/
function move_dir( $from, $to ) {
global $wp_filesystem;

$result = false;
if ( ! defined( 'WPINC' ) ) {
die;
}

if ( ! function_exists( 'move_dir' ) ) {
/**
* Fires before move_dir().
* Moves a directory from one location to another via the rename() PHP function.
* If the renaming failed, falls back to copy_dir().
*
* Assumes that WP_Filesystem() has already been called and setup.
*
* @since 6.1.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param string $from Source directory.
* @param string $to Destination directory.
* @return true|WP_Error True on success, WP_Error on failure.
*/
do_action( 'pre_move_dir' );
function move_dir( $from, $to ) {
global $wp_filesystem;

if ( 'direct' === $wp_filesystem->method ) {
$wp_filesystem->rmdir( $to );
$result = false;

$result = @rename( $from, $to );
}
/**
* Fires before move_dir().
*
* @since 6.1.0
*/
do_action( 'pre_move_dir' );

// Non-direct filesystems use some version of rename without a fallback.
if ( 'direct' !== $wp_filesystem->method ) {
$result = $wp_filesystem->move( $from, $to );
}
if ( 'direct' === $wp_filesystem->method ) {
$wp_filesystem->rmdir( $to );

if ( ! $result ) {
if ( ! $wp_filesystem->is_dir( $to ) ) {
if ( ! $wp_filesystem->mkdir( $to, FS_CHMOD_DIR ) ) {
return new \WP_Error( 'mkdir_failed_move_dir', __( 'Could not create directory.' ), $to );
}
$result = @rename( $from, $to );
}

$result = copy_dir( $from, $to, [ basename( $to ) ] );
// Non-direct filesystems use some version of rename without a fallback.
if ( 'direct' !== $wp_filesystem->method ) {
$result = $wp_filesystem->move( $from, $to );
}

// Clear the source directory.
if ( ! is_wp_error( $result ) ) {
$wp_filesystem->delete( $from, true );
if ( ! $result ) {
if ( ! $wp_filesystem->is_dir( $to ) ) {
if ( ! $wp_filesystem->mkdir( $to, FS_CHMOD_DIR ) ) {
return new \WP_Error( 'mkdir_failed_move_dir', __( 'Could not create directory.' ), $to );
}
}

$result = copy_dir( $from, $to, [ basename( $to ) ] );

// Clear the source directory.
if ( ! is_wp_error( $result ) ) {
$wp_filesystem->delete( $from, true );
}
}

/**
* Fires after move_dir().
*
* @since 6.1.0
*/
do_action( 'post_move_dir' );

return $result;
}
}

if ( ! function_exists( 'str_contains' ) ) {
/**
* Fires after move_dir().
* Polyfill for `str_contains()` function added in PHP 8.0.
*
* @since 6.1.0
* Performs a case-sensitive check indicating if needle is
* contained in haystack.
*
* @since 5.9.0
*
* @param string $haystack The string to search in.
* @param string $needle The substring to search for in the haystack.
* @return bool True if `$needle` is in `$haystack`, otherwise false.
*/
do_action( 'post_move_dir' );
function str_contains( $haystack, $needle ) {
return ( '' === $needle || false !== strpos( $haystack, $needle ) );
}
}

return $result;
if ( ! function_exists( 'str_starts_with' ) ) {
/**
* Polyfill for `str_starts_with()` function added in PHP 8.0.
*
* Performs a case-sensitive check indicating if
* the haystack begins with needle.
*
* @since 5.9.0
*
* @param string $haystack The string to search in.
* @param string $needle The substring to search for in the `$haystack`.
* @return bool True if `$haystack` starts with `$needle`, otherwise false.
*/
function str_starts_with( $haystack, $needle ) {
if ( '' === $needle ) {
return true;
}
return 0 === strpos( $haystack, $needle );
}
}

if ( ! function_exists( 'str_ends_with' ) ) {
/**
* Polyfill for `str_ends_with()` function added in PHP 8.0.
*
* Performs a case-sensitive check indicating if
* the haystack ends with needle.
*
* @since 5.9.0
*
* @param string $haystack The string to search in.
* @param string $needle The substring to search for in the `$haystack`.
* @return bool True if `$haystack` ends with `$needle`, otherwise false.
*/
function str_ends_with( $haystack, $needle ) {
if ( '' === $haystack && '' !== $needle ) {
return false;
}
$len = strlen( $needle );
return 0 === substr_compare( $haystack, $needle, -$len, $len );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ public function __construct( $string ) {
&& false === strpos( $string, "\n" )
&& file_exists( $string )
)
|| preg_match( '!^https?://!i', $string )
|| preg_match( '!^data:text/plain!i', $string) )
|| preg_match( '!^https?://!i', $string )
|| preg_match( '!^data:text/plain!i', $string) )
{
$this->parse_readme( $string );
} elseif ( $string ) {
Expand Down
10 changes: 10 additions & 0 deletions vendor/composer/autoload_files.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

// autoload_files.php @generated by Composer

$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);

return array(
'f1ec494b6996a8b9d9e80ad0c590bdf0' => $baseDir . '/src/Git_Updater/Shim.php',
);
19 changes: 19 additions & 0 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ public static function getLoader()

$loader->register(true);

$includeFiles = \Composer\Autoload\ComposerStaticInita27e6a3df8c435e2b136f961f0442be2::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequirea27e6a3df8c435e2b136f961f0442be2($fileIdentifier, $file);
}

return $loader;
}
}

/**
* @param string $fileIdentifier
* @param string $file
* @return void
*/
function composerRequirea27e6a3df8c435e2b136f961f0442be2($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

require $file;
}
}
4 changes: 4 additions & 0 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

class ComposerStaticInita27e6a3df8c435e2b136f961f0442be2
{
public static $files = array (
'f1ec494b6996a8b9d9e80ad0c590bdf0' => __DIR__ . '/../..' . '/src/Git_Updater/Shim.php',
);

public static $prefixLengthsPsr4 = array (
'F' =>
array (
Expand Down
4 changes: 2 additions & 2 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => 'afragen/git-updater',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'e49e60476c4b403d12c83f654aa16fdf0b6a1055',
'reference' => '68696207fdac567de6911c8107edb0ab0e9ed8ee',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'afragen/git-updater' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'e49e60476c4b403d12c83f654aa16fdf0b6a1055',
'reference' => '68696207fdac567de6911c8107edb0ab0e9ed8ee',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down

0 comments on commit f956441

Please sign in to comment.