YahnisElsts / plugin-update-checker

A custom update checker for WordPress plugins. Useful if you don't want to host your project in the official WP repository, but would still like it to support automatic updates. Despite the name, it also works with themes.
MIT License
2.22k stars 404 forks source link

Plugin sees no update in child site #375

Closed haulrich closed 4 years ago

haulrich commented 4 years ago

I've set up your plugin to work with our self-hosted Gitlab instance, in an internal project repo. Authentication via token works well so far.

I've installed a master, and a child site. I FTP (by lack of SSH on shared hosting) updates to the master site, and immediately commit them to Gitlab. Thus, the master site is always up to date with Gitlab. The child site only knows about updates via Gitlab changes.

In the child site, I installed your plugin, and authentication works. I set the branch to 'live' and hoped for the best. I pushed my master to live.

In installed Debug Bar so I could hit the debug check immediately.

What should I do to make it signal me for an update?

YahnisElsts commented 4 years ago

In general, changing the Version header in style.css should be enough to trigger an update. The update checker won't check tags when you're using a custom branch.

Since you have Debug Bar installed, could you please try clicking "Request Info"? Does it show the correct version number, or does it display the old version or an error of some kind?

haulrich commented 4 years ago

Hmm, very helpful point. In my barebones setup I guess I miss some vital info there. Thanks for your very quick help on this.

Puc_v4p9_Plugin_Info Object
(
    [name] => 
    [slug] => themename
    [version] => 
    [homepage] => 
    [sections] => Array
        (
            [changelog] => Er is geen changelog beschikbaar.
        )
...
)

The changelog error says there's no changelog available.

Should I add this info in my repository settings, and how?

haulrich commented 4 years ago

Maybe I'm digging too deep, but I can't find what I should change, easily.

In my theme, I refer as the Theme URI to the site where the theme is (not yet) installed.

However, if I look up the TwentyThirteen theme, it points to this: https://wordpress.org/themes/twentythirteen/

And in the content of the site I find this:

<script type="text/javascript">
/* <![CDATA[ */
var _wpThemeSettings = {"themes":"","query":{"themes":[{"name":"Twenty Thirteen","slug":"twentythirteen","version":"3.0","preview_url":"https:\/\/wp-themes.com\/twentythirteen","author":{"user_nicename":"wordpressdotorg","profile":"https:\/\/profiles.wordpress.org\/wordpressdotorg","avatar":"https:\/\/secure.gravatar.com\/avatar\/61ee2579b8905e62b4b4045bdc92c11a?s=96&d=monsterid&r=g","display_name":"WordPress.org"},"screenshot_url":"https:\/\/i0.wp.com\/themes.svn.wordpress.org\/twentythirteen\/3.0\/screenshot.png","theme_url":"https:\/\/wordpress.org\/themes\/twentythirteen\/","ratings":{"1":"5","2":"3","3":"8","4":"12","5":"34"},"rating":82,"num_ratings":"62","active_installs":90000,"last_updated":"2020-03-31","homepage":"https:\/\/wordpress.org\/themes\/twentythirteen\/","description":"The 2013 theme for WordPress takes us back to the blog, featuring a full range of post formats, each displayed beautifully in their own unique way. Design details abound, starting with a vibrant color scheme and matching header images, beautiful typography and icons, and a flexible layout that looks great on any device, big or small.","download_link":"https:\/\/downloads.wordpress.org\/theme\/twentythirteen.3.0.zip","tags":{"accessibility-ready":"Accessibility Ready","blog":"Blog","custom-header":"Custom Header","custom-menu":"Custom Menu","editor-style":"Editor Style","featured-images":"Featured Images","footer-widgets":"Footer Widgets","microformats":"Microformats","one-column":"One Column","post-formats":"Post Formats","right-sidebar":"Right Sidebar","rtl-language-support":"RTL Language Support","sticky-post":"Sticky Post","translation-ready":"Translation Ready","two-columns":"Two Columns"},"requires":"3.6","requires_php":"5.2.4"}],"request":{"theme":"twentythirteen"},"total":1,"pages":1},"settings":{"title":{"default":"%s &#124; WordPress.org","home":"WordPress Themes &#124; WordPress.org","theme":"%s - WordPress theme &#124; WordPress.org","author":"Themes by %s &#124; WordPress.org","tax":"WordPress Themes: %s Free &#124; WordPress.org","search":"Search Results for &#8220;%s&#8221; &#124; WordPress.org","notfound":"Page not found &#124; WordPress.org"},"isMobile":false,"postsPerPage":"12","path":"\/themes\/","locale":"en_US","favorites":{"themes":[],"user":false,"nonce":false},"browseDefault":"popular"},"l10n":{"locale":"en-US","search":"Search Themes","searchPlaceholder":"Search themes...","error":"An unexpected error occurred.","date":"Date","downloads":"Downloads","tags":{"grid-layout":"Grid Layout","one-column":"One Column","two-columns":"Two Columns","three-columns":"Three Columns","four-columns":"Four Columns","left-sidebar":"Left Sidebar","right-sidebar":"Right Sidebar","wide-blocks":"Wide Blocks","fixed-layout":"Fixed Layout","fluid-layout":"Fluid Layout","responsive-layout":"Responsive Layout","accessibility-ready":"Accessibility Ready","block-patterns":"Block Editor Patterns","block-styles":"Block Editor Styles","buddypress":"BuddyPress","custom-background":"Custom Background","custom-colors":"Custom Colors","custom-header":"Custom Header","custom-logo":"Custom Logo","custom-menu":"Custom Menu","editor-style":"Editor Style","featured-image-header":"Featured Image Header","featured-images":"Featured Images","flexible-header":"Flexible Header","footer-widgets":"Footer Widgets","front-page-post-form":"Front Page Posting","full-site-editing":"Full Site Editing","full-width-template":"Full Width Template","microformats":"Microformats","post-formats":"Post Formats","rtl-language-support":"RTL Language Support","sticky-post":"Sticky Post","theme-options":"Theme Options","threaded-comments":"Threaded Comments","translation-ready":"Translation Ready","blavatar":"Blavatar","blog":"Blog","e-commerce":"E-Commerce","education":"Education","entertainment":"Entertainment","food-and-drink":"Food & Drink","holiday":"Holiday","news":"News","photography":"Photography","portfolio":"Portfolio","photoblogging":"Photoblogging","seasonal":"Seasonal","black":"Black","blue":"Blue","brown":"Brown","gray":"Gray","green":"Green","orange":"Orange","pink":"Pink","purple":"Purple","red":"Red","silver":"Silver","tan":"Tan","white":"White","yellow":"Yellow","dark":"Dark","light":"Light"},"active_installs_less_than_10":"Less than 10","active_installs_1_million":"1+ million"}};
/* ]]> */
</script>

I can create a structure like that. Should I?

YahnisElsts commented 4 years ago

Here's something that stands out to me: it's a theme, but the info class name is Puc_v4p9_Plugin_Info. This suggests that the update checker is treating it as a plugin instead of a theme. This could be a configuration issue or some kind of a bug/edge case in the code that's supposed to automatically detect if the thing being updated is a plugin or theme.

Could you show me your update checker initialisation code? Feel free to remove any identifying information.

haulrich commented 4 years ago

Indeed, I see a difference now....!

I followed these steps, and didn't spot the difference in the call. Of course I understand you cannot put in examples for every case, people should read ...

require 'plugin-update-checker/plugin-update-checker.php';
$myUpdateChecker = new Puc_v4p9_Vcs_PluginUpdateChecker(
    new Puc_v4p9_Vcs_GitLabApi('https://gitlab.mydomain.net/project/themename'),
    __FILE__,
    'themename'
);
//Optional: If you're using a private repository, specify the access token like this:
$myUpdateChecker->setAuthentication('token');

And this is where I go wrong. I see it now.

I think the right object to use is

Puc_v4p9_Vcs_ThemeUpdateChecker

...I'm going to try it now. (on a Friday afternoon...)

haulrich commented 4 years ago

Yes, finally - I now get a fitting overview, and it says I've got an update! Thanks for helping me further. Also, the update shows up in the WP updates screen as well.

But, updating goes awry.... I think my filestructure is wrong.

Warning: copy(): The first argument to copy() function cannot be a directory in /var/www/vhosts/domain.net/install/wp-admin/includes/class-wp-filesystem-direct.php on line 281
Updating theme failed.

There was an error in updating /var/www/vhosts/domain.net/install/blabla/theme/functions.php: Unable to rename the update to match the existing directory..

In scrambling the data, I used some blabber-words. I think this error is more a WP thing than it has to do with your system... But have you seen it before, and could you give me a hint to why it says it can't update?

haulrich commented 4 years ago

Currently, I moved all my theme files to the root directory. But if I read your code, it looks like it throws this last error because the files are not in a subdirectory...?

So in my repo, the subdirs are now /css/ /img/ and such. I could refactor it to start with /themename/ and put everything below that.

But I just altered that earlier today, because the updater plugin couldn't seem to find the functions.php (well, fault of that could be my PluginUpdater call) .

YahnisElsts commented 4 years ago

The expected file structure is this:

In the ZIP file that contains the update, all of the files should be inside a subdirectory. Ideally, the subdirectory name should match the theme directory name, but the update checker can usually automatically fix the name if it has to.

In the repository all files should be in the root directory. Yes, this is inconsistent with the previous paragraph. The reason why the update checker was designed that way has to do with how other repositories (e.g. GitHub) package the files when creating a release or a branch/tag archive.

I think GitLab.com automatically puts the files in a subdirectory when creating a ZIP file - or at least it did the last time I tested it. I'm not sure if the same applies to the self-hosted version of GitLab.

haulrich commented 4 years ago

Good morning! Thanks for the response on Friday.

I think I understand the needed structure; I'm not sure I understand the working now.

First, this is what I see in the WP updater screen: image

I think I should not see two things: 1) the server path name, while it should state the name of the theme? 2) it says 'you have version ... installed' , no version number.

I think I have been too minimal in setting up the theme. Could you point me to where I should put that? I tried the style.css and the readme.txt ...

image

To confirm: I downloaded the .zip from the url in the check, named 'download_url'. This url successfully points me to a .zip which downloads, and in it are directly the theme contents, from the root. So no subfolder inside the zip with a custom hosted Gitlab. It 1:1 matches the structure in the repo itself.

YahnisElsts commented 4 years ago

I agree, it should show the theme name and not the file path. This strange output prompted me to double-check the update checker initialisation code and I noticed something that I had missed before: those constructor arguments would be fine for Puc_v4p9_PluginUpdateChecker, but they are not correct for Puc_v4p9_ThemeUpdateChecker. For a theme, the second argument should be they full path to style.css, not the __FILE__ constant.

Try something like this instead:

$myUpdateChecker = new Puc_v4p9_Vcs_ThemeUpdateChecker(
    new Puc_v4p9_Vcs_GitLabApi('https://gitlab.mydomain.net/project/themename'),
    __DIR__ . '/style.css', // <-- this is the important part.
    'themename'
);
haulrich commented 4 years ago

I've tried, I've tried... but no luck so far. I copied your line with the style.css.

Noticed the slashes everywhere thoroughly. They match.

Checking for updates goes well.

But the updater itself still gives me the warning like above, though now for style.css. "First argument to copy() can't be a directory."

image

haulrich commented 4 years ago

Also, I have no caching plugins running.

YahnisElsts commented 4 years ago

It looks like it's still not showing the theme name. How about this:

$myUpdateChecker = new Puc_v4p9_Vcs_ThemeUpdateChecker(
    new Puc_v4p9_Vcs_GitLabApi('https://gitlab.mydomain.net/project/themename'),
    basename(__DIR__), // <-- directory name instead of the full path
    'themename'
);
haulrich commented 4 years ago

My goodness it WORKS!

I'm so happy with this!! It now shows the theme name, and after I upped the version number and pushed to Gitlab, it said it had an update. Updated perfectly on the child site. This is beautiful.

Thank you so much!

YahnisElsts commented 4 years ago

All right, that's good to hear.

I'll close this issue now.