Skip to content

Commit

Permalink
WIP for retrieving the uploaded file from the plugin uploader modal
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeTowers committed Aug 4, 2024
1 parent bb95ba6 commit 46c1a83
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions modules/system/controllers/Updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
use System\Models\Parameter;
use System\Models\PluginVersion;
use Winter\Storm\Database\Model;
use Winter\Storm\Database\Models\DeferredBinding;
use Winter\Storm\Exception\ApplicationException;
use Winter\Storm\Support\Facades\File;
use Winter\Storm\Support\Facades\Flash;
use Winter\Storm\Support\Facades\Html;
use Winter\Storm\Support\Facades\Markdown;
use Winter\Storm\Support\Str;

/**
* Updates controller
Expand Down Expand Up @@ -794,7 +796,31 @@ public function onLoadPluginUploader(): string
public function onInstallUploadedPlugin(): string
{
try {
// Get the deferred binding record for the uploaded file
$widget = $this->getPackageUploadWidget();
$class = Str::before(get_class($widget->model), chr(0));
$deferred = DeferredBinding::query()
->where('master_type', 'LIKE', str_replace('\\', '\\\\', $class) . '%')
->where('master_field', 'uploaded_package')
->where('session_key', $widget->getSessionKey())
->first();

// Attempt to get the file from the deferred binding
if (!$deferred || !$deferred->slave) {
throw new ApplicationException(Lang::get('system::lang.server.response_invalid'));
}
$file = $deferred->slave;

/**
* @TODO:
* - Process the uploaded file to identify the plugins to install
* - (optional) require confirmation to install each detected plugin
* - Install the identified plugins
* - Ensure that deferred binding records and uploaded files are removed post processing or on failure
*/

$manager = UpdateManager::instance();

$result = $manager->installUploadedPlugin();

if (!isset($result['code']) || !isset($result['hash'])) {
Expand Down Expand Up @@ -824,6 +850,8 @@ public function onInstallUploadedPlugin(): string
return $this->makePartial('execute');
}
catch (Exception $ex) {
// @TODO: Remove this, temporary debugging
throw $ex;
$this->handleError($ex);
return $this->makePartial('plugin_uploader');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div id="pluginUploadPopup">
<?= Form::ajax('onInstallUploadedPlugin', [
'data-popup-load-indicator' => true,
'data-request-data' => 'type:plugin',
]) ?>
<input type="hidden" name="type" value="plugin">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title"><?= e(trans('system::lang.plugins.upload')) ?></h4>
Expand Down

0 comments on commit 46c1a83

Please sign in to comment.