Error when trying to update plugin
Closed this issue · 2 comments
Everything seems to be working ok except for the final step of actually updating the plugin.
When I try clicking the update button I get the following error:
Update Failed: The package could not be installed. PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature
I have done a bit of Googling on this error message and it's commonly associated with bad zip files or not enough server resources but I am very very confident this isn't the issue in my case because I have tried my own plugins and also existing well established plugins like Akismet and they all get the same error. I have also tried running the updates on my local server (MAMP) and on a typical live Apache server and they are all getting the same error message.
As you know from my previous issue I am running this as a plugin. My plugins code is blank it's not checking for anything so the download should just work. Here is a metadata url:
https://northernbeacheswebsites.com.au/?update_action=get_metadata&update_slug=akismet
and my plugin code is like follows:
<?php
/*
Plugin Name: Plugin Update Server
Description: An example plugin that runs the update API.
Version: 1.0
Author: Yahnis Elsts
Author URI: http://w-shadow.com/
*/
require_once __DIR__ . '/wp-update-server/loader.php';
class ExamplePlugin {
protected $updateServer;
public function __construct() {
$this->updateServer = new MyCustomServer(home_url('/'));
//The "action" and "slug" query parameters are often used by the WordPress core
//or other plugins, so lets use different parameter names to avoid conflict.
add_filter('query_vars', array($this, 'addQueryVariables'));
add_action('template_redirect', array($this, 'handleUpdateApiRequest'));
}
public function addQueryVariables($queryVariables) {
$queryVariables = array_merge($queryVariables, array(
'update_action',
'update_slug',
));
return $queryVariables;
}
public function handleUpdateApiRequest() {
if ( get_query_var('update_action') ) {
$this->updateServer->handleRequest(array_merge($_GET, array(
'action' => get_query_var('update_action'),
'slug' => get_query_var('update_slug'),
)));
}
}
}
class MyCustomServer extends Wpup_UpdateServer {
}
$examplePlugin = new ExamplePlugin();
Do you know why this error may be occurring? Thanks,
I tried to manually download the update and got the site homepage instead of a ZIP file. It looks like this is because download_url
still has the old query parameters action
and slug
where it should have update_action
and update_slug
. To fix that, you'll need to override the generateDownloadUrl
method as shown in the "Running the server from another script" example:
protected function generateDownloadUrl(Wpup_Package $package) {
$query = array(
'update_action' => 'download',
'update_slug' => $package->slug,
);
return self::addQueryArg($query, $this->serverUrl);
}
Ahh thanks so much, I must have somehow removed this from my code. Everything is up and running now so I won't bother you any more. Your plugin and assistance have been fantastic, I really appreciate it.