Commit 34fdd917e5f9e5a1f843b6630e45a4e621ff721e

Authored by Paul Barrett
1 parent f40e4039

Added auto register to Email Plugin. Added error message return from KTAPIDocum…

…ent if the plugin is not enabled but the document email function is invoked.

KTS-4406. KT Email plugin is not enabled by default & no error returned by webservice on attempting to use KT Email plugin

Fixed

Committed by: Paul Barrett

Reviewed by: Jarrett Jordaan
ktapi/KTAPIDocument.inc.php
... ... @@ -665,7 +665,8 @@ class KTAPI_Document extends KTAPI_FolderItem
665 665 }
666 666 else
667 667 {
668   - return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.');
  668 + return new PEAR_Error('A document with this title already exists in your chosen folder. '
  669 + . 'Please choose a different folder, or specify a new title for the copied document.');
669 670 }
670 671 }
671 672  
... ... @@ -685,7 +686,8 @@ class KTAPI_Document extends KTAPI_FolderItem
685 686 }
686 687 else
687 688 {
688   - return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.');
  689 + return new PEAR_Error('A document with this filename already exists in your chosen folder. '
  690 + . 'Please choose a different folder, or specify a new filename for the copied document.');
689 691 }
690 692 }
691 693  
... ... @@ -806,7 +808,8 @@ class KTAPI_Document extends KTAPI_FolderItem
806 808 }
807 809 if ($clash)
808 810 {
809   - return new PEAR_Error('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the moved document.');
  811 + return new PEAR_Error('A document with this title already exists in your chosen folder. '
  812 + . 'Please choose a different folder, or specify a new title for the moved document.');
810 813 }
811 814  
812 815 $filename=$this->document->getFilename();
... ... @@ -819,7 +822,8 @@ class KTAPI_Document extends KTAPI_FolderItem
819 822 }
820 823 if ($clash)
821 824 {
822   - return new PEAR_Error('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the moved document.');
  825 + return new PEAR_Error('A document with this filename already exists in your chosen folder. '
  826 + . 'Please choose a different folder, or specify a new filename for the moved document.');
823 827 }
824 828  
825 829 DBUtil::startTransaction();
... ... @@ -2427,7 +2431,8 @@ class KTAPI_Document extends KTAPI_FolderItem
2427 2431  
2428 2432 /**
2429 2433 * Emails a document as an attachment or hyperlink to a list of users, groups or external email addresses.
2430   - * In the case of external addresses, if a hyperlink is used then a timed download link (via webservices) is sent allowing the recipient a window period in which to download the document.
  2434 + * In the case of external addresses, if a hyperlink is used then a timed download link (via webservices) is sent
  2435 + * allowing the recipient a window period in which to download the document.
2431 2436 * The period is set through the webservices config option webservice/downloadExpiry. Defaults to 30 minutes.
2432 2437 *
2433 2438 * @author KnowledgeTree Team
... ... @@ -2435,12 +2440,18 @@ class KTAPI_Document extends KTAPI_FolderItem
2435 2440 * @param array $members The email recipients - KTPAI_Users, KTAPI_Groups or email addresses
2436 2441 * @param string $comment Content to be appended to the email
2437 2442 * @param bool $attachDocument TRUE if document is an attachment | FALSE if using a hyperlink to the document
  2443 + *
  2444 + * NOTE this function requires that the Email Plugin be active.
  2445 + * It seems that it is possible for this to be unintentionally turned off during a plugin re-read.
2438 2446 */
2439 2447 public function email($members, $comment, $attachDocument = true)
2440 2448 {
2441   - if (empty($members))
2442   - {
2443   - return;
  2449 + // check for active email plugin
  2450 + if (!KTPluginUtil::pluginIsActive('ktstandard.email.plugin')) {
  2451 + return new PEAR_Error('Email Plugin is not active');
  2452 + }
  2453 + if (empty($members)) {
  2454 + return new PEAR_Error('No recipients specified');
2444 2455 }
2445 2456  
2446 2457 $userIds = array();
... ... @@ -2449,16 +2460,13 @@ class KTAPI_Document extends KTAPI_FolderItem
2449 2460  
2450 2461 foreach($members as $member)
2451 2462 {
2452   - if ($member instanceof KTAPI_User)
2453   - {
  2463 + if ($member instanceof KTAPI_User) {
2454 2464 $userIds[] = $member->Id;
2455 2465 }
2456   - elseif ($member instanceof KTAPI_Group)
2457   - {
  2466 + else if ($member instanceof KTAPI_Group) {
2458 2467 $groupIds[] = $member->Id;
2459 2468 }
2460   - elseif (is_string($member))
2461   - {
  2469 + else if (is_string($member)) {
2462 2470 $emailAddrs[] = $member;
2463 2471 }
2464 2472 }
... ... @@ -2468,12 +2476,12 @@ class KTAPI_Document extends KTAPI_FolderItem
2468 2476 $allowEmailAddresses = $config->get('email/allowEmailAddresses', false);
2469 2477  
2470 2478 // if attachments aren't allowed, set $attachDocument to false
2471   - if(!$allowAttachment){
  2479 + if(!$allowAttachment) {
2472 2480 $attachDocument = false;
2473 2481 }
2474 2482  
2475 2483 // If sending to external email addresses is not allowed - set array of external recipients to empty
2476   - if(!$allowEmailAddresses){
  2484 + if(!$allowEmailAddresses) {
2477 2485 $emailAddrs = array();
2478 2486 }
2479 2487  
... ... @@ -2482,19 +2490,16 @@ class KTAPI_Document extends KTAPI_FolderItem
2482 2490 $listEmails = array();
2483 2491  
2484 2492 sendGroupEmails($groupIds, $userEmails, $emailErrors);
2485   -
2486 2493 sendUserEmails($userIds, $userEmails, $emailErrors);
2487 2494  
2488   - if ($attachDocument)
2489   - {
  2495 + if ($attachDocument) {
2490 2496 sendManualEmails($emailAddrs, $userEmails, $emailErrors);
2491 2497 }
2492   - else
2493   - {
  2498 + else {
2494 2499 sendExternalEmails($emailAddrs, $this->documentid, $this->get_title(), $comment, $emailErrors);
2495 2500 }
2496 2501  
2497   - if(empty($userEmails)){
  2502 + if(empty($userEmails)) {
2498 2503 return;
2499 2504 }
2500 2505  
... ...
ktapi/ktapi.inc.php
... ... @@ -2678,7 +2678,12 @@ class KTAPI
2678 2678 }
2679 2679 }
2680 2680  
2681   - $document->email($recipients, $content, $attach);
  2681 + $result = $document->email($recipients, $content, $attach);
  2682 +
  2683 + if (PEAR::isError($result)) {
  2684 + $response['message'] = $result->getMessage();
  2685 + return $response;
  2686 + }
2682 2687  
2683 2688 $response['status_code'] = 0;
2684 2689 return $response;
... ...
plugins/ktstandard/KTEmail.php
... ... @@ -580,6 +580,7 @@ class KTDocumentEmailAction extends KTDocumentAction {
580 580  
581 581 class KTEmailPlugin extends KTPlugin {
582 582 var $sNamespace = 'ktstandard.email.plugin';
  583 + var $autoRegister = true;
583 584  
584 585 function KTEmailPlugin($sFilename = null) {
585 586 $res = parent::KTPlugin($sFilename);
... ...