Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodor Truffer committed Feb 18, 2021
1 parent 53860ae commit 3c806a4
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 17 deletions.
9 changes: 5 additions & 4 deletions classes/class.ilOneDriveActionListGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected function rename()
$form = $this->buildForm();
if (!$form->checkInput()) {
$response->success = false;
$response->message = ilUtil::getSystemMessageHTML($this->txt('msg_invalid_input'), "failure");
$response->message = $DIC->ui()->mainTemplate()->getMessageHTML($this->txt('msg_invalid_input'), "failure");
echo json_encode($response);
exit;
}
Expand All @@ -192,14 +192,15 @@ protected function rename()
$this->getService()->getClient()->renameItemById($id, $title);
EventLogger::logObjectRenamed(
$DIC->user()->getId(),
$exoItem->getPath(),
$this->getPluginObject()->getObjId(),
$exoItem->getFullPath(),
$title,
ObjectType::fromExodItem($exoItem)
);
$response->message = ilUtil::getSystemMessageHTML($this->txt("msg_renamed"), "success");
$response->message = $DIC->ui()->mainTemplate()->getMessageHTML($this->txt("msg_renamed"), "success");
$response->success = true;
} catch (Exception $e) {
$response->message = ilUtil::getSystemMessageHTML($e->getMessage(), "failure");
$response->message = $DIC->ui()->mainTemplate()->getMessageHTML($e->getMessage(), "failure");
}

$response->id = $id;
Expand Down
1 change: 1 addition & 0 deletions classes/class.ilOneDriveDeleteGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function deleteItem()
$response->success = true;
EventLogger::logObjectDeleted(
$DIC->user()->getId(),
$this->getPluginHookObject()->getId(),
$node->getPath(),
ObjectType::fromExodItem(exodItemCache::get($node->getId()))
);
Expand Down
2 changes: 1 addition & 1 deletion classes/class.ilOneDriveSettingsGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function showLogs()
$DIC->tabs()->activateTab('settings');
$this->initSubtabs(self::SUBTAB_LOGS);
$DIC->ui()->mainTemplate()->setContent(
(new EventLogTableUI($DIC))->render()
(new EventLogTableUI($DIC, $this->getPluginObject()->getObjId()))->render()
);
}

Expand Down
5 changes: 5 additions & 0 deletions classes/class.ilOneDriveUploadGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ protected function afterUpload()
$parent_id = $_SESSION["cld_folder_id"];
EventLogger::logUploadComplete(
$DIC->user()->getId(),
$this->getPluginObject()->getObjId(),
ilCloudFileTree::getFileTreeFromSession()->getNodeFromId($parent_id)->getPath() . '/' . $name
);
}
Expand All @@ -123,6 +124,7 @@ protected function asyncGetResumableUploadUrl()
} catch (ilCloudException $e) {
EventLogger::logUploadFailed(
$DIC->user()->getId(),
$this->getPluginObject()->getObjId(),
$file_path,
$e->getMessage()
);
Expand All @@ -131,6 +133,7 @@ protected function asyncGetResumableUploadUrl()
}
EventLogger::logUploadStarted(
$DIC->user()->getId(),
$this->getPluginObject()->getObjId(),
$file_path,
$name_sanitized === $name ? '' : $name
);
Expand All @@ -148,6 +151,7 @@ protected function uploadFailed()
$file_path = ilCloudFileTree::getFileTreeFromSession()->getNodeFromId($parent_id)->getPath() . '/' . $name;
EventLogger::logUploadFailed(
$DIC->user()->getId(),
$this->getPluginObject()->getObjId(),
$file_path,
$message ?? ''
);
Expand All @@ -161,6 +165,7 @@ protected function uploadAborted()
$file_path = ilCloudFileTree::getFileTreeFromSession()->getNodeFromId($parent_id)->getPath() . '/' . $name;
EventLogger::logUploadAborted(
$DIC->user()->getId(),
$this->getPluginObject()->getObjId(),
$file_path
);
}
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"issues": "https://plugins.studer-raimann.ch/goto.php?target=uihk_srsu_PLONEDRIVE"
},
"require": {
"php": ">=7.0"
"php": ">=7.0",
"srag/custominputguis": ">=0.1.0",
"srag/librariesnamespacechanger": ">=0.1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -37,5 +39,8 @@
"sort-packages": true
},
"scripts": {
"pre-autoload-dump": [
"srag\\LibrariesNamespaceChanger\\LibrariesNamespaceChanger::rewriteLibrariesNamespaces"
]
}
}
24 changes: 24 additions & 0 deletions src/EventLog/EventLogEntryAR.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class EventLogEntryAR extends ActiveRecord
* @con_sequence true
*/
protected $id;
/**
* @var int
* @con_has_field true
* @con_fieldtype integer
* @con_is_notnull true
* @con_length 8
*/
protected $obj_id;
/**
* @var string
* @con_has_field true
Expand Down Expand Up @@ -82,6 +90,22 @@ public function getId() : int
return $this->id;
}

/**
* @return int
*/
public function getObjId() : int
{
return $this->obj_id;
}

/**
* @param int $obj_id
*/
public function setObjId(int $obj_id)
{
$this->obj_id = $obj_id;
}

/**
* @return string
*/
Expand Down
14 changes: 14 additions & 0 deletions src/EventLog/EventLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ class EventLogger
{
public static function logUploadStarted(
int $user_id,
int $obj_id,
string $file_path,
string $renamed_from = ''
) {
self::log(
$user_id,
$obj_id,
EventType::uploadStarted(),
$file_path,
ObjectType::file(),
Expand All @@ -23,10 +25,12 @@ public static function logUploadStarted(

public static function logUploadComplete(
int $user_id,
int $obj_id,
string $file_path
) {
self::log(
$user_id,
$obj_id,
EventType::uploadComplete(),
$file_path,
ObjectType::file(),
Expand All @@ -36,10 +40,12 @@ public static function logUploadComplete(

public static function logUploadAborted(
int $user_id,
int $obj_id,
string $file_path
) {
self::log(
$user_id,
$obj_id,
EventType::uploadAborted(),
$file_path,
ObjectType::file(),
Expand All @@ -49,11 +55,13 @@ public static function logUploadAborted(

public static function logUploadFailed(
int $user_id,
int $obj_id,
string $file_path,
string $message = ''
) {
self::log(
$user_id,
$obj_id,
EventType::uploadFailed(),
$file_path,
ObjectType::file(),
Expand All @@ -63,11 +71,13 @@ public static function logUploadFailed(

public static function logObjectDeleted(
int $user_id,
int $obj_id,
string $object_path,
ObjectType $object_type
) {
self::log(
$user_id,
$obj_id,
EventType::objectDeleted(),
$object_path,
$object_type,
Expand All @@ -77,12 +87,14 @@ public static function logObjectDeleted(

public static function logObjectRenamed(
int $user_id,
int $obj_id,
string $object_path_old,
string $object_name_new,
ObjectType $object_type
) {
self::log(
$user_id,
$obj_id,
EventType::objectRenamed(),
$object_path_old,
$object_type,
Expand All @@ -92,12 +104,14 @@ public static function logObjectRenamed(

protected static function log(
int $user_id,
int $obj_id,
EventType $event_type,
string $object_path,
ObjectType $object_type,
array $additional_data
) {
$entry = new EventLogEntryAR();
$entry->setObjId($obj_id);
$entry->setTimestamp(date('Y-m-d H:i:s', time()));
$entry->setEventType($event_type);
$entry->setUserId($user_id);
Expand Down
10 changes: 8 additions & 2 deletions src/EventLog/UI/EventLogTableUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
*/
class EventLogTableUI
{
/**
* @var int
*/
private $obj_id;
/**
* @var Container
*/
Expand All @@ -20,10 +24,12 @@ class EventLogTableUI
/**
* EventLogTableUI constructor.
* @param Container $dic
* @param int $obj_id
*/
public function __construct(Container $dic)
public function __construct(Container $dic, int $obj_id)
{
$this->dic = $dic;
$this->obj_id = $obj_id;
}

public function render() : string
Expand All @@ -37,7 +43,7 @@ public function render() : string
: $value[1];
});
return $arrayForConnector;
}, EventLogEntryAR::get());
}, EventLogEntryAR::where(['obj_id' => $this->obj_id])->get());
return '<script type="application/javascript">' .
'window.exod_log_data = ' . json_encode(array_values($data)) . ';' .
'window.lng = "' . $this->dic->language()->getLangKey() . '";' .
Expand Down
11 changes: 10 additions & 1 deletion src/Input/ChunkedFileUpload/js/ChunkedUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ initChunkedUpload = (
after_upload_callback,
url_upload_aborted,
url_upload_failed,
url_session_refresh,
submit_cmd
) => {
let $submit_btn = $('input[name="cmd[' + submit_cmd + ']"]');
Expand All @@ -17,7 +18,7 @@ initChunkedUpload = (
$filename_input.val(file ? file.name : '');
$submit_btn.prop("disabled", (!file && !!submit_cmd));
});
$('#form_' + form_id).on('submit', (event) => {
$submit_btn.on('click', (event) => {
let file = $input.get(0).files[0];
event.preventDefault();
il.waiter.show();
Expand All @@ -33,6 +34,7 @@ initChunkedUpload = (
response = JSON.parse(response);
// callback functions
$input.on('fileuploaddone', (e, data) => {
clearInterval(this.session_refresher);
il.waiter.hide();
this.file_in_progress = undefined;
if (typeof after_upload_callback !== 'undefined') {
Expand All @@ -41,6 +43,7 @@ initChunkedUpload = (
}).on('fileuploadprogress', (e, data) => {
il.waiter.setBytes(data.loaded, data.total);
}).on('fileuploadfail', (e, data) => {
clearInterval(this.session_refresher);
$.ajax({
type: 'post',
url: url_upload_failed,
Expand All @@ -51,6 +54,11 @@ initChunkedUpload = (
alert('Error: ' + data.errorThrown)
});

// session refresher every 5 minutes for very long uploads 300000
this.session_refresher = setInterval(() => {
$.get(url_session_refresh);
}, 300000);

// init chunked upload
$input.fileupload('send', {
files: file,
Expand All @@ -60,6 +68,7 @@ initChunkedUpload = (
multipart: false
});
}).fail((err) => {
clearInterval(this.session_refresher);
il.waiter.hide();
const error_json = JSON.parse(err.responseText);
alert(error_json.error.message + "<br>Please contact an administrator.");
Expand Down
2 changes: 1 addition & 1 deletion src/Input/ChunkedFileUpload/js/ChunkedUpload.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
class srChunkedDirectFileUploadInputGUI extends ilFormPropertyGUI
{
const DEFAULT_CHUNK_SIZE = 327680 * 20;
const DEFAULT_CHUNK_SIZE = 327680 * 40;
/**
* @var string
*/
Expand Down Expand Up @@ -103,6 +103,11 @@ public static function loadJavaScript(ilTemplate $a_tpl, bool $force = false)
}
}

protected function getSessionRefreshUrl()
{
return ILIAS_HTTP_PATH;
}

/**
* @param string $input_id
* @return string
Expand All @@ -117,10 +122,11 @@ protected function getOnloadCode(string $input_id) : string
'"' . $this->getAfterUploadJsCallback() . '",' .
'"' . $this->getUploadAbortedUrl() . '",' .
'"' . $this->getUploadFailedUrl() . '",' .
'"' . $this->getSessionRefreshUrl() . '",' .
'"' . ($this->getRequired() ? $this->submit_cmd : "") . '")';
}

public function render()
public function render() : string
{
$tmp_id = ilUtil::randomhash();
$this->tpl->setVariable('LABEL', $this->dic->language()->txt('select_file'));
Expand Down
10 changes: 5 additions & 5 deletions src/Util/Waiter/Waiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ private function __construct(){}

/**
* @param string $type
* @param ilTemplate $ilTemplate
*/
public static final function init(string $type, ilTemplate $ilTemplate)/*: void*/
public static final function init(string $type)/*: void*/
{
global $DIC;
if (self::$init === false) {
self::$init = true;

$dir = __DIR__;
$dir = "./" . substr($dir, strpos($dir, "/Customizing/") + 1);

$ilTemplate->addCss($dir . "/css/waiter.css");
$DIC->ui()->mainTemplate()->addCss($dir . "/css/waiter.css");

$ilTemplate->addJavaScript($dir . "/js/waiter.min.js");
$DIC->ui()->mainTemplate()->addJavaScript($dir . "/js/waiter.min.js");
}

$ilTemplate->addOnLoadCode('il.waiter.init("' . $type . '");');
$DIC->ui()->mainTemplate()->addOnLoadCode('il.waiter.init("' . $type . '");');
}
}

0 comments on commit 3c806a4

Please sign in to comment.