Skip to content

Commit dff8850

Browse files
committed
fix: Fixed automatic updater
1 parent 8d179f6 commit dff8850

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

GithubUpdater.php

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class GithubUpdater
99
private ?string $repository;
1010
private string $asset_name;
1111
private string $readme_url;
12-
12+
private string $slug = 'wp-openid-siu-upm'; // Forzamos el slug correcto
1313

1414
public static function make(): self
1515
{
@@ -20,7 +20,7 @@ public function boot(string $file): self
2020
{
2121
$this->file = $file;
2222
$this->plugin = get_plugin_data($this->file);
23-
$this->basename = plugin_basename($this->file);
23+
$this->basename = $this->slug . '/' . basename($this->file); // Usamos el slug forzado
2424
$this->active = is_plugin_active($this->basename);
2525

2626
if ($this->repository) {
@@ -58,7 +58,7 @@ public function modify_transient($transient)
5858
// No update, return a fake update to enable auto update check
5959
$transient->no_update[$this->basename] = (object)[
6060
'id' => $this->basename,
61-
'slug' => dirname($this->basename),
61+
'slug' => $this->slug, // Usamos el slug correcto
6262
'plugin' => $this->basename,
6363
'new_version' => $this->plugin['Version'],
6464
'url' => '',
@@ -82,14 +82,14 @@ public function plugin_popup($result, $action, $args)
8282
}
8383

8484
if (!empty($args->slug)) {
85-
if ($args->slug == current(explode('/', $this->basename))) {
85+
if ($args->slug == $this->slug) { // Comparar con el slug forzado
8686
$gh = $this->_get_repository();
8787

8888
$plugin = [
8989
'name' => $this->plugin['Name'],
90-
'slug' => $this->basename,
90+
'slug' => $this->slug, // Usamos el slug correcto
9191
'requires' => '5.0',
92-
'tested' => '6.6.1',
92+
'tested' => '6.6.2',
9393
'version' => $gh['tag_name'],
9494
'author' => $this->plugin['AuthorName'],
9595
'author_profile' => $this->plugin['AuthorURI'],
@@ -113,17 +113,50 @@ public function plugin_popup($result, $action, $args)
113113
public function after_install($response, $hook_extra, $result)
114114
{
115115
global $wp_filesystem;
116-
116+
117117
$install_directory = plugin_dir_path($this->file);
118-
$wp_filesystem->move($result['destination'], $install_directory);
119-
$result['destination'] = $install_directory;
120-
118+
$new_directory = trailingslashit(WP_PLUGIN_DIR) . $this->slug; // Ruta de la carpeta renombrada
119+
120+
// Mueve el directorio descargado al nuevo directorio
121+
$wp_filesystem->move($result['destination'], $new_directory);
122+
123+
// Actualiza la propiedad basename con el nuevo directorio
124+
$this->basename = plugin_basename($new_directory . '/' . basename($this->file));
125+
$result['destination'] = $new_directory;
126+
127+
// Actualizar las referencias en la base de datos
128+
$this->update_database_references();
129+
130+
// Reactiva el plugin si estaba activo antes
121131
if ($this->active) {
122132
activate_plugin($this->basename);
123133
}
124-
134+
125135
return $result;
126136
}
137+
138+
private function update_database_references()
139+
{
140+
// Obtener la lista de plugins activos
141+
$active_plugins = get_option('active_plugins', []);
142+
143+
// Buscar la referencia antigua del plugin en los plugins activos y reemplazarla
144+
$old_basename = plugin_basename($this->file); // Referencia antigua
145+
$new_basename = $this->slug . '/' . basename($this->file); // Nueva referencia
146+
147+
if (in_array($old_basename, $active_plugins)) {
148+
// Reemplazar la referencia antigua por la nueva en la lista de plugins activos
149+
$active_plugins = array_map(function ($plugin) use ($old_basename, $new_basename) {
150+
return ($plugin === $old_basename) ? $new_basename : $plugin;
151+
}, $active_plugins);
152+
153+
// Guardar la nueva lista de plugins activos
154+
update_option('active_plugins', $active_plugins);
155+
}
156+
157+
// Actualizar otros datos de configuración relacionados, si es necesario
158+
$this->update_plugin_options($old_basename, $new_basename);
159+
}
127160

128161
private function _get_repository(): array
129162
{
@@ -155,7 +188,7 @@ private function _get_update_from_repository(): ?object
155188
if ($asset) {
156189
return (object)[
157190
'id' => $this->basename,
158-
'slug' => dirname($this->basename),
191+
'slug' => $this->slug, // Usamos el slug correcto
159192
'plugin' => $this->basename,
160193
'new_version' => $response_version,
161194
'url' => $response['url'],

0 commit comments

Comments
 (0)