Skip to content

Commit

Permalink
Fix various issues
Browse files Browse the repository at this point in the history
  • Loading branch information
orzuionut committed May 31, 2019
1 parent a57be00 commit 1ae5c61
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 92 deletions.
38 changes: 3 additions & 35 deletions w2g2/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,7 @@

namespace OCA\w2g2;

use OCA\w2g2\Notification\Notifier;
use \OCA\w2g2\AppInfo\Application;


class App {
const name = 'w2g2';
const table = 'locks_w2g2';

public static function launch()
{
if ( ! \OC::$server->getUserSession()->getUser()) {
return;
}

\OCP\Util::addScript(self::name, 'w2g2');

\OCP\Util::addStyle(self::name, 'styles');
}
}

if (\OC::$server->getAppManager()->isEnabledForUser(App::name)) {
App::launch();

$notificationManager = \OC::$server->getNotificationManager();
$notificationManager->registerNotifier(
function() {
$Application = new \OCP\AppFramework\App('w2g2');

return $Application->getContainer()->query(Notifier::class);
},
function () {
$l = \OC::$server->getL10N('w2g2');

return ['id' => 'w2g2', 'name' => $l->t('w2g2')];
}
);
}
$app = new Application();
$app->boot();
3 changes: 1 addition & 2 deletions w2g2/appinfo/database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
<field>
<name>created</name>
<type>timestamp</type>
<default>CURRENT_TIMESTAMP</default>
</field>
</declaration>
</table>
</database>
</database>
2 changes: 1 addition & 1 deletion w2g2/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</description>
<licence>AGPL</licence>
<author>Ionut Orzu</author>
<version>2.2.6</version>
<version>2.2.7</version>
<category>social</category>
<category>files</category>

Expand Down
1 change: 0 additions & 1 deletion w2g2/js/w2g2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
var checkStateUrl = OC.generateUrl('/apps/w2g2/lock');
var directoryLockUrl = OC.generateUrl('/apps/w2g2/directory-lock');
var colorUrl = OC.generateUrl('/apps/w2g2/color');
var lockstate = t('w2g2', 'Locked');

$(document).ready(function () {
getBackgroundColor();
Expand Down
52 changes: 52 additions & 0 deletions w2g2/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace OCA\w2g2\AppInfo;

use OCP\AppFramework\App;
use OCA\w2g2\Notification\Notifier;

class Application extends App
{
const name = 'w2g2';

public function __construct()
{
parent::__construct(self::name);
}

public function boot()
{
if ( ! \OC::$server->getAppManager()->isEnabledForUser(self::name)) {
return;
}

$this->registerHooks();
$this->registerScripts();
}

public function registerHooks()
{
$notificationManager = \OC::$server->getNotificationManager();
$notificationManager->registerNotifier(
function() {
$Application = new \OCP\AppFramework\App('w2g2');

return $Application->getContainer()->query(Notifier::class);
},
function () {
$l = \OC::$server->getL10N('w2g2');

return ['id' => 'w2g2', 'name' => $l->t('w2g2')];
}
);
}

public function registerScripts()
{
$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function() {
script(self::name, 'w2g2');
style(self::name, 'styles');
});
}
}
9 changes: 8 additions & 1 deletion w2g2/lib/Db/AdminMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ public function getLocks()
}
} else if ($fileIndex === 0) {
$filePath = substr($lockedFiles[$i]['path'], strlen('files/'));
$lockedFiles[$i]['path'] = $lockedFiles[$i]['locked_by'] . '/' . $filePath;

$path = $lockedFiles[$i]['locked_by'] . '/' . $filePath;

if ($lockedFiles[$i]['created']) {
$path .= ' --- Created: ' . $lockedFiles[$i]['created'];
}

$lockedFiles[$i]['path'] = $path;
}
}

Expand Down
10 changes: 7 additions & 3 deletions w2g2/lib/Db/LockMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(IDbConnection $db)

public function all()
{
$query = "SELECT f.path, f.fileid, l.locked_by FROM " . $this->tableName . " AS l JOIN *PREFIX*" . 'filecache' . " as f ON l.file_id = f.fileid";
$query = "SELECT f.path, f.fileid, l.locked_by, l.created FROM " . $this->tableName . " AS l JOIN *PREFIX*" . 'filecache' . " as f ON l.file_id = f.fileid";

return $this->db->executeQuery($query)
->fetchAll();
Expand All @@ -35,9 +35,13 @@ public function findAll()

public function store(Lock $lock)
{
$sql = 'INSERT INTO ' . $this->tableName . ' (file_id, locked_by) VALUES (?, ?)';
$sql = 'INSERT INTO ' . $this->tableName . ' (file_id, locked_by, created) VALUES (?, ?, ?)';

$this->db->executeQuery($sql, [$lock->getFileId(), $lock->getLockedBy()]);
$this->db->executeQuery($sql, [
$lock->getFileId(),
$lock->getLockedBy(),
date('Y-m-s H:i:s')
]);
}

public function deleteOne(Lock $lock)
Expand Down
8 changes: 7 additions & 1 deletion w2g2/lib/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ public function isGroupFolder()

public function getParentId()
{
return ($this->getCompleteData())['parent'];
$data = $this->getCompleteData();

if ( ! $data) {
return null;
}

return $data['parent'];
}

public function getCompleteData()
Expand Down
96 changes: 48 additions & 48 deletions w2g2/templates/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,42 +64,42 @@ class="color"
<br>

<?php
if (count($_['lockedFiles']) > 0) {
?>
if (count($_['lockedFiles']) > 0) {
?>

<div id="lockfield">
<label for="select_lock"> <?php p($l->t("Locked files")) ?>: </label>
<div id="lockfield">
<label for="select_lock"> <?php p($l->t("Locked files")) ?>: </label>

<br>
<br>

<select size="6"
style="height:100px; min-width: 400px;"
id="select_lock">'
<select size="6"
style="height:100px; min-width: 400px;"
id="select_lock">'

<?php for ($i = 0; $i < count($_['lockedFiles']); $i++) { ?>
<option value="<?php p($_['lockedFiles'][$i]['fileid']) ?>">
<?php p(rtrim($_['lockedFiles'][$i]['path'], '/')) ?>
</option>
<?php } ?>
</select>
<?php for ($i = 0; $i < count($_['lockedFiles']); $i++) { ?>
<option value="<?php p($_['lockedFiles'][$i]['fileid']) ?>">
<?php p(rtrim($_['lockedFiles'][$i]['path'], '/')) ?>
</option>
<?php } ?>
</select>

<br>
<br>

<input id="clearthis"
type="submit"
value="<?php p($l->t("Unlock this file")) ?>"
name=clearthis">
<input id="clearthis"
type="submit"
value="<?php p($l->t("Unlock this file")) ?>"
name=clearthis">

<input id="clearall"
type="submit"
value="<?php p($l->t("Unlock all files")) ?>"
name=clearall">
</div>
<input id="clearall"
type="submit"
value="<?php p($l->t("Unlock all files")) ?>"
name=clearall">
</div>

<?php
} else {
p($l->t("There are no locked files at the moment"));
}
<?php
} else {
p($l->t("There are no locked files at the moment"));
}
?>

<br>
Expand All @@ -121,11 +121,11 @@ class="color"
<input id="rule_username"
type="radio"
name="suffix"
<?php
if ($_['lockingByUsername']) {
p('checked');
}
?>
<?php
if ($_['lockingByUsername']) {
p('checked');
}
?>
>

<label for="rule_username">
Expand All @@ -141,13 +141,13 @@ class="color"

<p>
<input id="rule_displayname"
type="radio"
type="radio"
name="suffix"
<?php
if ($_['lockingByDisplayName']) {
p('checked');
}
?>
<?php
if ($_['lockingByDisplayName']) {
p('checked');
}
?>
>

<label for="rule_displayname">
Expand Down Expand Up @@ -179,9 +179,9 @@ class="color"
<input id="directory_locking_all"
type="radio"
name="directory_locking"
<?php if ($_['directoryLockingAll']) {
p('checked');
} ?>
<?php if ($_['directoryLockingAll']) {
p('checked');
} ?>
>

<label for="directory_locking_all">
Expand All @@ -193,9 +193,9 @@ class="color"
<input id="directory_locking_files"
type="radio"
name="directory_locking"
<?php if ($_['directoryLockingFiles']) {
p('checked');
} ?>
<?php if ($_['directoryLockingFiles']) {
p('checked');
} ?>
>

<label for="directory_locking_files">
Expand All @@ -207,9 +207,9 @@ class="color"
<input id="directory_locking_none"
type="radio"
name="directory_locking"
<?php if ($_['directoryLockingNone']) {
p('checked');
} ?>
<?php if ($_['directoryLockingNone']) {
p('checked');
} ?>
>

<label for="directory_locking_none">
Expand Down

0 comments on commit 1ae5c61

Please sign in to comment.