Overview
Comment:Possibilité de requérir une version minimale de Garradin pour un plugin. Enregistrement de la configuration déporté à la destruction de l'objet. Instanciation de $plugin avant l'installation.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bcc5556f06c78d3b086d4ba190d8b165c766b6bb
User & Date: bohwaz on 2014-12-18 16:43:38
Other Links: manifest | tags
Context
2014-12-18
18:41
Déplacement des objets pour adopter PSR-0 check-in: e1d5bc8368 user: bohwaz tags: trunk
16:43
Possibilité de requérir une version minimale de Garradin pour un plugin. Enregistrement de la configuration déporté à la destruction de l'objet. Instanciation de $plugin avant l'installation. check-in: bcc5556f06 user: bohwaz tags: trunk
16:06
Correction : group by mal situé check-in: 9efe281e4a user: bohwaz tags: trunk
Changes

Modified src/include/class.plugin.php from [76ff16e57c] to [290c0720a4].

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
<?php

namespace Garradin;

class Plugin
{
	protected $id = null;
	protected $plugin = null;


	protected $mimes = [
		'css' => 'text/css',
		'gif' => 'image/gif',
		'htm' => 'text/html',
		'html' => 'text/html',
		'ico' => 'image/x-ico',








>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php

namespace Garradin;

class Plugin
{
	protected $id = null;
	protected $plugin = null;
	protected $config_changed = false;

	protected $mimes = [
		'css' => 'text/css',
		'gif' => 'image/gif',
		'htm' => 'text/html',
		'html' => 'text/html',
		'ico' => 'image/x-ico',
44
45
46
47
48
49
50














51
52
53
54
55
56
57
		if (!is_array($this->plugin['config']))
		{
			$this->plugin['config'] = [];
		}

		$this->id = $id;
	}















	/**
	 * Renvoie le chemin absolu vers l'archive du plugin
	 * @return string Chemin PHAR vers l'archive
	 */
	public function path()
	{







>
>
>
>
>
>
>
>
>
>
>
>
>
>







45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
		if (!is_array($this->plugin['config']))
		{
			$this->plugin['config'] = [];
		}

		$this->id = $id;
	}

	/**
	 * Enregistrer les changements dans la config
	 */
	public function __destruct()
	{
		if ($this->config_changed)
		{
			$db = DB::getInstance();
			$db->simpleUpdate('plugins', 
				['config' => json_encode($this->plugin['config'])],
				'id = \'' . $this->id . '\'');
		}
	}

	/**
	 * Renvoie le chemin absolu vers l'archive du plugin
	 * @return string Chemin PHAR vers l'archive
	 */
	public function path()
	{
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
			unset($this->plugin['config'][$key]);
		}
		else
		{
			$this->plugin['config'][$key] = $value;
		}

		$db = DB::getInstance();
		$db->simpleUpdate('plugins', 
			['config' => json_encode($this->plugin['config'])],
			'id = \'' . $this->id . '\'');

		return true;
	}

	/**
	 * Renvoie une information ou toutes les informations sur le plugin
	 * @param  string $key Clé de l'info à retourner, ou NULL pour recevoir toutes les infos







<
<
<
|







107
108
109
110
111
112
113



114
115
116
117
118
119
120
121
			unset($this->plugin['config'][$key]);
		}
		else
		{
			$this->plugin['config'][$key] = $value;
		}




		$this->config_changed = true;

		return true;
	}

	/**
	 * Renvoie une information ou toutes les informations sur le plugin
	 * @param  string $key Clé de l'info à retourner, ou NULL pour recevoir toutes les infos
454
455
456
457
458
459
460





461
462
463
464
465
466
467
		foreach ($required as $key)
		{
			if (!array_key_exists($key, $infos))
			{
				throw new \RuntimeException('Le fichier garradin_plugin.ini ne contient pas d\'entrée "'.$key.'".');
			}
		}






		if (!empty($infos['menu']) && !file_exists('phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/www/admin/index.php'))
		{
			throw new \RuntimeException('Le plugin '.$id.' ne comporte pas de fichier www/admin/index.php alors qu\'il demande à figurer au menu.');
		}

		$config = '';







>
>
>
>
>







466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
		foreach ($required as $key)
		{
			if (!array_key_exists($key, $infos))
			{
				throw new \RuntimeException('Le fichier garradin_plugin.ini ne contient pas d\'entrée "'.$key.'".');
			}
		}

		if (!empty($infos['min_version']) && !version_compare(garradin_version(), $infos['min_version'], '>='))
		{
			throw new \RuntimeException('Le plugin '.$id.' nécessite Garradin version '.$infos['min_version'].' ou supérieure.');
		}

		if (!empty($infos['menu']) && !file_exists('phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/www/admin/index.php'))
		{
			throw new \RuntimeException('Le plugin '.$id.' ne comporte pas de fichier www/admin/index.php alors qu\'il demande à figurer au menu.');
		}

		$config = '';
501
502
503
504
505
506
507


508
509
510
511
512
513
514
			'version'	=>	$infos['version'],
			'menu'		=>	(int)(bool)$infos['menu'],
			'config'	=>	$config,
		]);

		if (file_exists('phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/install.php'))
		{


			include 'phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/install.php';
		}

		return true;
	}

	/**







>
>







518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
			'version'	=>	$infos['version'],
			'menu'		=>	(int)(bool)$infos['menu'],
			'config'	=>	$config,
		]);

		if (file_exists('phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/install.php'))
		{
			$plugin = new Plugin($id);

			include 'phar://' . PLUGINS_ROOT . '/' . $id . '.tar.gz/install.php';
		}

		return true;
	}

	/**