Commit bc90ced45c2efa53008112175f4150006b641cf6

Authored by kevin_fourie
1 parent 7b4108f5

Merged in from DEV trunk...

KTS-3208
"Error when adding external links to a document"
Fixed. Check if array is not empty before running the foreach

Committed by: Megan Watson
Reviewed by: Jonathan Byrne

KTS-3181
"Scheduler: Migration process fails"
Fixed. Divide by 1 if migrated documents is 0

Committed By: Megan Watson
Reviewed By: Kevin Fourie


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@8318 c91229c3-7414-0410-bfa2-8a42b809f60b
plugins/ktstandard/KTDocumentLinks.php
... ... @@ -288,18 +288,20 @@ class KTDocumentLinkAction extends KTDocumentAction {
288 288  
289 289 // select a type for the link
290 290 function do_type_select() {
291   -
  291 +
292 292 //Checking to see if the document is being linked to itself and returning an error if it is.
293 293 $iTempParentDocId = $_REQUEST['fDocumentId'];
294 294 $aTempDocuments = $_REQUEST['linkselection'];
295   - foreach ($aTempDocuments as $iTempDocId)
296   - {
297   - if($iTempParentDocId == $iTempDocId)
298   - {
299   - $this->errorRedirectToMain(_kt('A document cannot be linked to itself.'));
300   - }
  295 + if(!empty($aTempDocuments)){
  296 + foreach ($aTempDocuments as $iTempDocId)
  297 + {
  298 + if($iTempParentDocId == $iTempDocId)
  299 + {
  300 + $this->errorRedirectToMain(_kt('A document cannot be linked to itself.'));
  301 + }
  302 + }
301 303 }
302   -
  304 +
303 305 $this->oPage->setBreadcrumbDetails(_kt("link"));
304 306  
305 307 $sType = (isset($_REQUEST['linktype'])) ? $_REQUEST['linktype'] : 'internal';
... ... @@ -331,7 +333,8 @@ class KTDocumentLinkAction extends KTDocumentAction {
331 333 $aFields = array();
332 334  
333 335 $aVocab = array();
334   - foreach(LinkType::getList("id > 0") as $oLinkType) {
  336 + $aLinkTypes = LinkType::getList("id > 0");
  337 + foreach($aLinkTypes as $oLinkType) {
335 338 $aVocab[$oLinkType->getID()] = $oLinkType->getName();
336 339 }
337 340  
... ... @@ -562,8 +565,11 @@ class KTDocLinkAdminDispatcher extends KTAdminDispatcher {
562 565 foreach ($types_to_delete as $link_id) {
563 566 $oLinkType = LinkType::get($link_id);
564 567  
565   - foreach(DocumentLink::getList(sprintf("link_type_id = %d", $link_id)) as $oLink) {
566   - $oLink->delete();
  568 + $aLinks = DocumentLink::getList(sprintf("link_type_id = %d", $link_id));
  569 + if(!empty($aLinks)){
  570 + foreach($aLinks as $oLink) {
  571 + $oLink->delete();
  572 + }
567 573 }
568 574  
569 575 $oLinkType->delete(); // technically, this is a bad thing
... ...
plugins/search2/MigrationDashlet.php
... ... @@ -87,7 +87,10 @@ class LuceneMigrationDashlet extends KTBaseDashlet
87 87 $migrationStartString = date('Y-m-d H:i:s', $migrationStart);
88 88 $migrationTime = KTUtil::getSystemSetting('migrationTime',0);
89 89 $migrationPeriod = KTUtil::computePeriod($migrationTime, '');
90   - $timePerDocument = $migrationTime / ($migratedDocuments > 0) ? $migratedDocuments : 1;
  90 +
  91 + // Cannot divide by zero so make it 1
  92 + $divMigratedDocuments = ($migratedDocuments > 0) ? $migratedDocuments : 1;
  93 + $timePerDocument = $migrationTime / $divMigratedDocuments;
91 94 $estimatedPeriod = $timePerDocument * $migratingDocuments;
92 95 $estimatedTime = date('Y-m-d H:i:s', $migrationStart + $estimatedPeriod);
93 96 $estimatedPeriod = KTUtil::computePeriod($estimatedPeriod, '');
... ...