Merge branch 'feature/es6_revamp' of github.com:getgrav/grav-plugin-admin into feature/es6_revamp

This commit is contained in:
Djamil Legato
2016-03-01 11:03:57 -08:00
2 changed files with 56 additions and 2 deletions

View File

@@ -476,6 +476,56 @@ class Admin
}); });
} }
/**
* Generate an array of nested dependencies for a package
*
* @param string $slug The package slug
* @param bool $remove_duplicates True if should remove duplicates after first occurrence
* @param array $keys_already_added Used for recursion
*
* @return array|bool
*/
public function dependencies($slug, $remove_duplicates = false, $keys_already_added = [])
{
$gpm = $this->gpm();
if (!$gpm) {
return false;
}
$package = $this->plugins(true)[$slug];
if (!$package) {
$package = $this->themes(true)[$slug];
}
$dependencies = [];
if ($package) {
if ($package->dependencies) {
if (!$keys_already_added) {
$keys_already_added = array_values($package->dependencies);
}
foreach ($package->dependencies as $dependency) {
$temp_dependencies = $this->dependencies($dependency, $keys_already_added);
if ($remove_duplicates) {
foreach($keys_already_added as $key => $value) {
if (is_string($value)) {
unset($temp_dependencies[$value]);
}
}
}
$keys_already_added = array_merge($keys_already_added, array_values($temp_dependencies));
$dependencies[$dependency] = $temp_dependencies;
}
}
}
return $dependencies;
}
/** /**
* Get all themes. * Get all themes.
* *

View File

@@ -9,10 +9,16 @@ use Grav\Common\GPM\Upgrader;
use Grav\Common\Filesystem\Folder; use Grav\Common\Filesystem\Folder;
use Grav\Common\GPM\Common\Package; use Grav\Common\GPM\Common\Package;
/**
* Class Gpm
* @package Grav\Plugin\Admin
*/
class Gpm class Gpm
{ {
// Probably should move this to Grav DI container? // Probably should move this to Grav DI container?
/** @var GravGPM */
protected static $GPM; protected static $GPM;
public static function GPM() public static function GPM()
{ {
if (!static::$GPM) { if (!static::$GPM) {
@@ -86,8 +92,6 @@ class Gpm
Installer::install($local, $options['destination'], ['install_path' => $package->install_path, 'theme' => $options['theme']]); Installer::install($local, $options['destination'], ['install_path' => $package->install_path, 'theme' => $options['theme']]);
Folder::delete(dirname($local)); Folder::delete(dirname($local));
$errorCode = Installer::lastErrorCode();
if (Installer::lastErrorCode() & (Installer::ZIP_OPEN_ERROR | Installer::ZIP_EXTRACT_ERROR)) { if (Installer::lastErrorCode() & (Installer::ZIP_OPEN_ERROR | Installer::ZIP_EXTRACT_ERROR)) {
return false; return false;
} }