Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit e68985f

Browse files
author
Michael Grauer
committed
BUG: refs #0373. Cleaned signature of createNewRevision method.
Cleaned up the signature of the createNewItemRevision method, and made some changes in related areas for improved readability. I found that the number of parameters in the new signature violated a style check, which is probably why the signature is as it was, but that seems like an arbitrary limit, and I don't think it should get in the way of clarity of a method signature.
1 parent 4111051 commit e68985f

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

core/controllers/UploadController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,13 @@ public function saveuploadedAction()
345345
$license = $this->_getParam('license');
346346
if(!empty($path) && file_exists($path))
347347
{
348-
$tmp = explode('-', $parent);
349-
if(count($tmp) == 2) //means we upload a new revision
348+
$itemId_itemRevisionNumber = explode('-', $parent);
349+
if(count($itemId_itemRevisionNumber) == 2) //means we upload a new revision
350350
{
351351
$changes = $this->_getParam('changes');
352-
$this->Component->Upload->createNewRevision($this->userSession->Dao, $filename, $path, $tmp, $changes, $license);
352+
$itemId = $itemId_itemRevisionNumber[0];
353+
$itemRevisionNumber = $itemId_itemRevisionNumber[1];
354+
$this->Component->Upload->createNewRevision($this->userSession->Dao, $filename, $path, $changes, $itemId, $itemRevisionNumber, $license);
353355
}
354356
else
355357
{

core/controllers/components/UploadComponent.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public function createUploadedItem($userDao, $name, $path, $parent = null, $lice
262262
}//end createUploadedItem
263263

264264
/** save upload item in the DB */
265-
public function createNewRevision($userDao, $name, $path, $item_revision, $changes, $license = null, $filemd5 = '')
265+
public function createNewRevision($userDao, $name, $path, $changes, $itemId, $itemRevisionNumber = null, $license = null, $filemd5 = '')
266266
{
267267
if($userDao == null)
268268
{
@@ -278,21 +278,24 @@ public function createNewRevision($userDao, $name, $path, $item_revision, $chang
278278
$itemRevisionModel = $modelLoad->loadModel('ItemRevision');
279279
$feedpolicyuserModel = $modelLoad->loadModel('Feedpolicyuser');
280280

281-
$item = $itemModel->load($item_revision[0]);
281+
$item = $itemModel->load($itemId);
282282

283283
if($item == false)
284284
{
285285
throw new Zend_Exception('Unable to find item');
286286
}
287287

288-
$revisions = $item->getRevisions();
289288
$itemRevisionDao = null;
290-
foreach($revisions as $revision)
289+
if(isset($itemRevisionNumber))
291290
{
292-
if($item_revision[1] == $revision->getRevision())
291+
$revisions = $item->getRevisions();
292+
foreach($revisions as $revision)
293293
{
294-
$itemRevisionDao = $revision;
295-
break;
294+
if($itemRevisionNumber == $revision->getRevision())
295+
{
296+
$itemRevisionDao = $revision;
297+
break;
298+
}
296299
}
297300
}
298301

@@ -360,7 +363,7 @@ public function createNewRevision($userDao, $name, $path, $item_revision, $chang
360363
}
361364
$itemRevisionModel->addBitstream($itemRevisionDao, $bitstreamDao);
362365
// now that we have updated the itemRevision, the item may be stale
363-
$item = $itemModel->load($item_revision[0]);
366+
$item = $itemModel->load($itemId);
364367

365368
$this->getLogger()->info(__METHOD__." Upload ok :".$path);
366369
Zend_Registry::get('notifier')->notifyEvent("EVENT_CORE_UPLOAD_FILE", array($itemRevisionDao->getItem()->toArray(), $itemRevisionDao->toArray()));

modules/api/controllers/components/ApiComponent.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,19 +427,22 @@ function uploadPerform($args)
427427
}
428428

429429
$uploadComponent = $componentLoader->loadComponent('Upload');
430+
$license = null;
430431
if(isset($folder))
431432
{
432-
$item = $uploadComponent->createUploadedItem($userDao, $filename, $filepath, $folder, '', $filemd5);
433+
$item = $uploadComponent->createUploadedItem($userDao, $filename, $filepath, $folder, $license, $filemd5);
433434
}
434435
else if(isset($revision))
435436
{
436-
$tmp = array($item->getKey(), $revision->getRevision()); //existing revision
437-
$item = $uploadComponent->createNewRevision($userDao, $filename, $filepath, $tmp, '', null, $filemd5);
437+
//an existing revision
438+
$changes = '';
439+
$item = $uploadComponent->createNewRevision($userDao, $filename, $filepath, $changes, $item->getKey(), $revision->getRevision(), $license, $filemd5);
438440
}
439441
else
440442
{
441-
$tmp = array($item->getKey(), 99999); //new revision
442-
$item = $uploadComponent->createNewRevision($userDao, $filename, $filepath, $tmp, '', null, $filemd5);
443+
// a new revision
444+
$changes = '';
445+
$item = $uploadComponent->createNewRevision($userDao, $filename, $filepath, $changes, $item->getKey(), $revision, $license, $filemd5);
443446
}
444447

445448
if(!$item)

tests/library/PhpCheckstyle/config/default.cfg.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150

151151
<!-- Checks for excessive parameters in a function declaration -->
152152
<test name="functionMaxParameters">
153-
<property name="maxParameters" value="7"/>
153+
<property name="maxParameters" value="8"/>
154154
</test>
155155

156156
<!-- Check Cyclomatic Complexity -->

0 commit comments

Comments
 (0)