-
Notifications
You must be signed in to change notification settings - Fork 11
Nette 2.4 compatibility #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
e53eac8
9c46056
570f0d6
6b06f4c
fb01df6
27d2bc9
db98b25
d4da69a
30a814a
bd73dcb
91614d6
7c2d610
683510a
4cbaf8b
d3a6884
6f9352f
c763cf5
e53bc11
27ef5c5
d30cb32
9aa59f3
adf2552
3f573d9
3820012
1494fbf
9ac871b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| /nbproject/ | ||
| /composer.lock | ||
| /Nette/ | ||
| /Nette/ | ||
| .idea/ | ||
| vendor/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <?php | ||
|
|
||
| namespace MultipleFileUpload; | ||
|
|
||
| use Nette; | ||
|
|
||
| class Extension extends Nette\DI\CompilerExtension | ||
| { | ||
|
|
||
| public function loadConfiguration() { | ||
| $builder = $this->getContainerBuilder(); | ||
| $this->compiler->parseServices($builder, $this->loadFromFile(__DIR__ . '/config.neon')); | ||
| } | ||
|
|
||
|
|
||
| public function beforeCompile() { | ||
| parent::beforeCompile(); | ||
| } | ||
|
|
||
|
|
||
| public function afterCompile(Nette\PhpGenerator\ClassType $class) { | ||
| $initialize = $class->methods['initialize']; | ||
|
|
||
| // add ->addMultipleFileUpload shortcut into forms | ||
| $initialize->addBody( | ||
| 'Nette\Forms\Container::extensionMethod( | ||
| "\Nette\Forms\Container::addMultipleFileUpload", | ||
| function (\Nette\Forms\Container $_this, $name, $label = null, $maxFileSize = 25) { | ||
| return $_this[$name] = new MultipleFileUpload\MultipleFileUpload($label, $maxFileSize, $this->getByType(?), $this->getByType(?)); | ||
| } | ||
| );', | ||
| ['Nette\Http\IRequest', 'MultipleFileUpload\UI\Registrator'] | ||
| ); | ||
|
|
||
| $initialize->addBody( | ||
| 'MultipleFileUpload\MultipleFileUpload::init( | ||
| $this->getByType(?), $this->getByType(?), $this->getByType(?) | ||
| );', | ||
| ['MultipleFileUpload\Model\IQueues', 'Nette\Http\IRequest', 'MultipleFileUpload\UI\Registrator'] | ||
| ); | ||
|
|
||
| $initialize->addBody( | ||
| '$this->getService(?)->onStartup[] = [?, ?];', | ||
| ['application', 'MultipleFileUpload\MultipleFileUpload', 'handleUploads'] | ||
| ); | ||
| $initialize->addBody( | ||
| '$this->getService(?)->onShutdown[] = [?, ?];', | ||
| ['application', 'MultipleFileUpload\MultipleFileUpload', 'cleanCache'] | ||
| ); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,9 @@ | |
|
|
||
| namespace MultipleFileUpload\Model\Dibi; | ||
|
|
||
| use dibi, | ||
| use DibiConnection, | ||
| MultipleFileUpload\Model\BaseQueues, | ||
| MultipleFileUpload\Model\IQueue, | ||
| Nette\InvalidStateException; | ||
| MultipleFileUpload\Model\IQueue; | ||
|
|
||
| /** | ||
| * Multiple File Uploader driver for Dibi | ||
|
|
@@ -28,13 +27,13 @@ class Queues extends BaseQueues | |
| * Path to directory of uploaded files (temp) | ||
| * @var string | ||
| */ | ||
| public static $uploadsTempDir; | ||
| public $uploadsTempDir; | ||
|
|
||
| /** | ||
| * Connection | ||
| * @var \DibiConnection | ||
| * @var DibiConnection | ||
| */ | ||
| public static $dibiConnection; | ||
| public $connection; | ||
|
|
||
|
|
||
| /** | ||
|
|
@@ -45,38 +44,24 @@ function initialize() | |
|
|
||
| } | ||
|
|
||
|
|
||
| // <editor-fold defaultstate="collapsed" desc="Database functions"> | ||
|
|
||
| /** | ||
| * Gets dibi connection | ||
| * @return \DibiConnection | ||
| */ | ||
| function getConnection() | ||
| public function __construct(string $tempDir, DibiConnection $conection) | ||
| { | ||
| if (!self::$dibiConnection) { | ||
| self::$dibiConnection = dibi::getConnection(); | ||
| $this->uploadsTempDir = $tempDir; | ||
| if(!file_exists($this->uploadsTempDir)) { | ||
| mkdir($this->uploadsTempDir, 0775, TRUE); | ||
| } | ||
| return self::$dibiConnection; | ||
| $this->conection = $conection; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the class variable is called connection so it should be $this->connection = $conection; |
||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Executes query | ||
| * @return \DibiResult | ||
| * @throws InvalidStateException | ||
| * @return DibiConnection | ||
| */ | ||
| function query() | ||
| public function getConnection() | ||
| { | ||
| $params = func_get_args(); | ||
| return call_user_func_array( | ||
| array($this->getConnection(), 'query'), $params | ||
| ); | ||
| return $this->database; | ||
| } | ||
|
|
||
|
|
||
| // </editor-fold> | ||
|
|
||
|
|
||
|
|
||
| /** | ||
| * Gets queue (create if needed) | ||
| * @param string $id | ||
|
|
@@ -95,7 +80,7 @@ function getQueue($id) | |
| */ | ||
| function createQueueObj($queueID) | ||
| { | ||
| $queue = new Queue(); | ||
| $queue = new Queue(); // todo: remove setQueuesModel --> move to __construct | ||
| $queue->setQueuesModel($this); | ||
| $queue->setQueueID($queueID); | ||
| $queue->initialize(); | ||
|
|
@@ -108,13 +93,13 @@ function createQueueObj($queueID) | |
| */ | ||
| function cleanup() | ||
| { | ||
| $this->getConnection()->begin(); | ||
| $this->connection->begin(); | ||
| foreach ($this->getQueues() AS $queue) { | ||
| if ($queue->getLastAccess() < time() - $this->getLifeTime()) { | ||
| $queue->delete(); | ||
| } | ||
| } | ||
| $this->getConnection()->commit(); | ||
| $this->connection->commit(); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -136,4 +121,4 @@ function getQueues() | |
| } | ||
|
|
||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,7 +72,7 @@ function addFileManually($name, $chunk, $chunks); | |
| * @param type $chunk | ||
| * @param FileUpload $file | ||
| */ | ||
| function updateFile($name, $chunk, FileUpload $file = null); | ||
| function updateFile($name, $chunk, FileUpload $file); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @akyn84 why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put this question conversely: is there special reason to have optional parameter?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly. :) |
||
|
|
||
| /** | ||
| * Gets all files in queue | ||
|
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only note: the latest version of dibi has Dibi\Connection instead of DibiConnection.. it would be nice to be compatible with latest dibi