-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use FileCreatedFromTemplateEvent to inject the already existing empty…
… template files for Collabora Signed-off-by: Julius Härtl <[email protected]> Cleanup template loading Signed-off-by: Julius Härtl <[email protected]> Fix template handling Signed-off-by: Julius Härtl <[email protected]>
- Loading branch information
1 parent
ea882d3
commit 1c87f3d
Showing
13 changed files
with
299 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) 2019, Roeland Jago Douma <[email protected]> | ||
* | ||
* @author Roeland Jago Douma <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\Richdocuments\Backgroundjobs; | ||
|
||
use OC\BackgroundJob\TimedJob; | ||
use OCA\Richdocuments\Service\CapabilitiesService; | ||
use OCP\DB\QueryBuilder\IQueryBuilder; | ||
use OCP\IDBConnection; | ||
|
||
class Cleanup extends TimedJob { | ||
|
||
/** @var IDBConnection */ | ||
private $db; | ||
|
||
public function __construct(IDBConnection $db) { | ||
$this->db = $db; | ||
|
||
$this->setInterval(60*60); | ||
} | ||
|
||
protected function run($argument) { | ||
// Expire template mappings for file creation | ||
$query = $this->db->getQueryBuilder(); | ||
$query->delete('richdocuments_template') | ||
->where($query->expr()->lte('timestamp', $query->createNamedParameter(time() - 60, IQueryBuilder::PARAM_INT))); | ||
$query->executeStatement(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/* | ||
* @copyright Copyright (c) 2021 Julius Härtl <[email protected]> | ||
* | ||
* @author Julius Härtl <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace OCA\Richdocuments\Listener; | ||
|
||
|
||
use OCA\Richdocuments\AppInfo\Application; | ||
use OCA\Richdocuments\TemplateManager; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Files\Template\FileCreatedFromTemplateEvent; | ||
use OCP\IConfig; | ||
|
||
class FileCreatedFromTemplateListener implements IEventListener { | ||
|
||
/** @var TemplateManager */ | ||
private $templateManager; | ||
|
||
public function __construct( | ||
TemplateManager $templateManager | ||
) { | ||
$this->templateManager = $templateManager; | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof FileCreatedFromTemplateEvent)) { | ||
return; | ||
} | ||
|
||
$templateFile = $event->getTemplate(); | ||
|
||
// Empty template | ||
if ($templateFile === null) { | ||
$event->getTarget()->putContent($this->templateManager->getEmptyFileContent($event->getTarget()->getExtension())); | ||
return; | ||
} | ||
|
||
if ($this->templateManager->isSupportedTemplateSource($templateFile->getExtension())) { | ||
// Only use TemplateSource if supported filetype | ||
$this->templateManager->setTemplateSource($event->getTarget()->getId(), $templateFile->getId()); | ||
} | ||
|
||
// Avoid having the mimetype of the source file set | ||
$event->getTarget()->getStorage()->getCache()->update($event->getTarget()->getId(), [ | ||
'mimetype' => $event->getTarget()->getMimeType() | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Richdocuments\Migration; | ||
|
||
use Closure; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
/** | ||
* Auto-generated migration step: Please modify to your needs! | ||
*/ | ||
class Version50200Date20211220212457 extends SimpleMigrationStep { | ||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
/** @var ISchemaWrapper $schema */ | ||
$schema = $schemaClosure(); | ||
|
||
if (!$schema->hasTable('richdocuments_template')) { | ||
$table = $schema->createTable('richdocuments_template'); | ||
$table->addColumn('id', 'bigint', [ | ||
'autoincrement' => true, | ||
'notnull' => true, | ||
'length' => 20, | ||
'unsigned' => true, | ||
]); | ||
$table->addColumn('userid', 'string', [ | ||
'notnull' => false, | ||
'length' => 64, | ||
]); | ||
$table->addColumn('fileid', 'bigint', [ | ||
'notnull' => true, | ||
'length' => 20, | ||
]); | ||
$table->addColumn('templateid', 'bigint', [ | ||
'notnull' => true, | ||
'length' => 20, | ||
]); | ||
$table->addColumn('timestamp', 'bigint', [ | ||
'notnull' => true, | ||
'length' => 20, | ||
'unsigned' => true, | ||
]); | ||
$table->setPrimaryKey(['id']); | ||
$table->addUniqueIndex(['userid', 'fileid'], 'rd_t_user_file'); | ||
} | ||
|
||
return $schema; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.