Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
fix module downloads with license
Browse files Browse the repository at this point in the history
  • Loading branch information
zegenie committed Dec 26, 2018
1 parent 6bdaf8f commit 645935e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
31 changes: 18 additions & 13 deletions core/entities/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace thebuggenie\core\entities;

use b2db\Update;
use thebuggenie\core\entities\common\IdentifiableScoped;
use thebuggenie\core\entities\tables\Modules;
use thebuggenie\core\entities\tables\Settings;
use thebuggenie\core\framework;
use b2db\Update,
thebuggenie\core\entities\common\IdentifiableScoped,
thebuggenie\core\entities\tables\Modules,
GuzzleHttp\Client as GuzzleClient,
thebuggenie\core\framework;

/**
* Module class, extended by all thebuggenie modules
Expand Down Expand Up @@ -487,24 +487,27 @@ public static function downloadPlugin($plugin_type, $plugin_key)
{
try
{
if (!framework\Settings::getLicenseIdentifier()) {
if (!framework\Settings::hasLicenseIdentifier()) {
throw new framework\exceptions\ModuleDownloadException("", framework\exceptions\ModuleDownloadException::MISSING_LICENSE);
}

$client = new \Net_Http_Client();
$client->get('https://thebuggenie.com/'.$plugin_type.'s/'.$plugin_key . '.json');
$plugin_json = json_decode($client->getBody());
$client = new GuzzleClient(['base_uri' => 'https://thebuggenie.com']);
$response = $client->get('/' . $plugin_type . 's/' . $plugin_key . '.json?license_key=' . framework\Settings::getLicenseIdentifier());

if ($response->getStatusCode() === 200) {
$plugin_json = json_decode($response->getBody());
}
}
catch (\Exception $e) {}

if (isset($plugin_json) && $plugin_json !== false) {
$filename = THEBUGGENIE_CACHE_PATH . $plugin_type . '_' . $plugin_json->key . '.zip';
$client->get($plugin_json->download);
if ($client->getResponse()->getStatus() != 200)
$response = $client->get($plugin_json->download);
if ($response->getStatusCode() != 200)
{
throw new framework\exceptions\ModuleDownloadException("", framework\exceptions\ModuleDownloadException::JSON_NOT_FOUND);
}
file_put_contents($filename, $client->getBody());
file_put_contents($filename, $response->getBody());
$module_zip = new \ZipArchive();
$module_zip->open($filename);
switch ($plugin_type) {
Expand All @@ -515,9 +518,11 @@ public static function downloadPlugin($plugin_type, $plugin_key)
$target_folder = THEBUGGENIE_PATH . 'themes';
break;
}
if (!is_writable($target_folder)) {
throw new framework\exceptions\ModuleDownloadException("", framework\exceptions\ModuleDownloadException::READONLY_TARGET);
}
$module_zip->extractTo(realpath($target_folder));
$module_zip->close();
unlink($filename);
} else {
throw new framework\exceptions\ModuleDownloadException("", framework\exceptions\ModuleDownloadException::FILE_NOT_FOUND);
}
Expand Down
1 change: 1 addition & 0 deletions core/framework/exceptions/ModuleDownloadException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ModuleDownloadException extends \Exception
const JSON_NOT_FOUND = 1;
const FILE_NOT_FOUND = 2;
const MISSING_LICENSE = 3;
const READONLY_TARGET = 4;

}

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<p><?= __('This is a list of modules that are available in the modules folder, but not currently installed on this system.'); ?></p>
<?php if (!$writable && $is_default_scope): ?>
<div class="message-box type-warning" id="module_message_writable_failure">
<span class="message"><?= fa_image_tag('folder') . __('The modules folder (%modules_path) seems to not be writable. You may not be able to install new modules.', array('%modules_path' => THEBUGGENIE_MODULES_PATH)); ?></span>
<span class="message"><?= fa_image_tag('folder') . __('The modules folder %modules_path seems to not be writable. You may not be able to install new modules.', array('%modules_path' => '<span class="command_box">' . THEBUGGENIE_MODULES_PATH . '</span>')); ?></span>
</div>
<?php endif; ?>
</div>
Expand All @@ -75,6 +75,11 @@
<?php endif; ?>
</div>
<div id="tab_install_pane" style="padding-top: 0; width: 100%; display: none;">
<?php if (!$writable && $is_default_scope): ?>
<div class="message-box type-warning" id="module_message_writable_failure">
<span class="message"><?= fa_image_tag('folder') . __('The modules folder %modules_path seems to not be writable. You may not be able to install new modules.', array('%modules_path' => '<span class="command_box">' . THEBUGGENIE_MODULES_PATH . '</span>')); ?></span>
</div>
<?php endif; ?>
<div id="available_modules_loading_indicator"><?= image_tag('spinning_16.gif'); ?></div>
<div id="available_modules_container" class="available_plugins_container plugins-list">

Expand Down
3 changes: 3 additions & 0 deletions core/modules/main/controllers/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ public function runUserdata(framework\Request $request)
case framework\exceptions\ModuleDownloadException::FILE_NOT_FOUND:
return $this->renderJSON(array('message' => $this->getI18n()->__('The module could not be downloaded')));
break;
case framework\exceptions\ModuleDownloadException::READONLY_TARGET:
return $this->renderJSON(array('title' => $this->getI18n()->__('Error extracting module zip'), 'message' => $this->getI18n()->__('Could not extract the module into the destination folder. Please check permissions.')));
break;
}
}
catch (\Exception $e)
Expand Down
12 changes: 12 additions & 0 deletions themes/oxygen/css/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,10 @@ input[type=checkbox].semi-checked {
.project-context.page-livelink_project_commit #content_container {
flex-direction: column;
}
.project-context.page-agile_board .project_info_container .project_right_container,
.project-context.page-agile_whiteboard .project_info_container .project_right_container {
max-width: none;
}

.side_bar {
flex: 0 0 310px;
Expand Down Expand Up @@ -14901,6 +14905,9 @@ table.sortable tr th.nosort {
.message-box .actions .button {
padding: 4px 7px;
}
.message-box .command_box {
font-size: .85em;
}

.greenbox {
background-color: rgba(177, 210, 143, 0.3);
Expand Down Expand Up @@ -16160,6 +16167,11 @@ form > .config_header {
border-spacing: 0 5px;
}

#config_modules #modules_menu_panes .message-box.type-warning {
margin: 10px 0;
width: 100%;
}

/* Project settings */

#project_settings input[type="text"], #project_settings input[type="email"],
Expand Down

0 comments on commit 645935e

Please sign in to comment.