Skip to content

Commit

Permalink
Reviewed code
Browse files Browse the repository at this point in the history
updated comments
Tested:
 - Multiple tickets and multiple patterns
 - update based on ticketmatchstring > add followup;
 - reopen based on ticketmatchstring > closed ticket;
 - reopen based on ticketmatchstring > solved ticket;
 - solve based on solvematchstring;
  • Loading branch information
DonutsNL committed Sep 27, 2023
1 parent 56842a0 commit 36e1ecb
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 65 deletions.
4 changes: 2 additions & 2 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
* ------------------------------------------------------------------------
*
* @package TicketFilter
* @version 1.1.0
* @version 1.2.0
* @author Chris Gralike
* @copyright Copyright (c) 2023 by Chris Gralike
* @license GPLv2+
* @see https://github.com/DonutsNL/ticketfilter/readme.md
* @link https://github.com/DonutsNL/ticketfilter
* @since 0.1
* @since 0.1.0
* ------------------------------------------------------------------------
**/

Expand Down
4 changes: 2 additions & 2 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
* ------------------------------------------------------------------------
*
* @package TicketFilter
* @version 1.1.0
* @version 1.2.0
* @author Chris Gralike
* @copyright Copyright (c) 2023 by Chris Gralike
* @license GPLv2+
* @see https://github.com/DonutsNL/ticketfilter/readme.md
* @link https://github.com/DonutsNL/ticketfilter
* @since 1.0
* @since 1.0.0
* ------------------------------------------------------------------------
**/
use Glpi\Plugin\Hooks;
Expand Down
35 changes: 18 additions & 17 deletions src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* ------------------------------------------------------------------------
*
* @package TicketFilter
* @version 1.1.0
* @version 1.2.0
* @author Chris Gralike
* @copyright Copyright (c) 2023 by Chris Gralike
* @license GPLv2+
Expand All @@ -49,6 +49,7 @@
class Filter {

/**
* PreItemAdd(Ticket item) : void -
* Method called by pre_item_add hook validates the object and passes
* it to the RegEx Matching then decides what to do.
*
Expand All @@ -67,11 +68,12 @@ public static function PreItemAdd(Ticket $item) : void

// Search our pattern in the name field and find corresponding ticket(s) (if any)
self::searchForMatches($item);
}
}
} // Not an array with expected keys
} // Not a valid object.
}

/**
* emptyReferencedObject(Ticket item) : void -
* Clean the referenced item and delete any mailbox items remaining
*
* @param Ticket $item The original ticket passed by the pre_item_add hook.
Expand All @@ -92,6 +94,7 @@ private static function emptyReferencedObject(Ticket $item) : void
}

/**
* searchForMatches(Ticket item) : bool -
* Perform a search in the glpi_tickets table using the searchString if one is found applying the
* provided ticket match patterns from dropdown on the ticket name (email subject).
*
Expand Down Expand Up @@ -166,31 +169,30 @@ private static function searchForMatches(Ticket $item) : bool
}

/**
* openMailGate(int Id) : MailCollector|null -
* Returns a connected mailCollector object or []
*
* @param int $Id Mail Collector ID
* @return MailCollector|null Union return types might be problematic with older php versions.
* @since 1.0.0
* @todo Move to separate non static Match class
* @since 1.0.0
*/
private static function openMailGate(int $Id) : MailCollector|null
{
// Create a mailCollector
if(is_numeric($Id)){
$mailCollector = new MailCollector();
$mailCollector->getFromDB((integer)$Id);
try {
$mailCollector->connect();
}catch (Throwable $e) {
Toolbox::logError('Error opening mailCollector', $e->getMessage(), "\n", $e->getTraceAsString());
Session::addMessageAfterRedirect(__('TicketFilter Could not connect to the mail receiver because of an error'), true, WARNING);
return null;
}
$mailCollector = new MailCollector();
$mailCollector->getFromDB((integer)$Id);
try {
$mailCollector->connect();
}catch (Throwable $e) {
Toolbox::logError('Error opening mailCollector', $e->getMessage(), "\n", $e->getTraceAsString());
Session::addMessageAfterRedirect(__('TicketFilter Could not connect to the mail receiver because of an error'), true, WARNING);
return null;
}
return $mailCollector;
}

/**
* deleteEmail(Ticket item) : bool -
* Delete original email from the mailbox to the accepted folder. This is not performed by the mailgate
* if the Ticket passed by reference is nullified as described in the hook documentation.
* This actually causes an error where mailgate leaves the email untouched.
Expand All @@ -209,8 +211,7 @@ private static function deleteEmail(Ticket $item) : bool
} else {
return false;
}
}

} // instantiation of mailCollector failed
return false;
}
}
14 changes: 10 additions & 4 deletions src/FilterPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* ------------------------------------------------------------------------
*
* @package TicketFilter
* @version 1.1.0
* @version 1.2.0
* @author Chris Gralike
* @copyright Copyright (c) 2023 by Chris Gralike
* @license GPLv2+
Expand All @@ -37,6 +37,7 @@
**/

namespace GlpiPlugin\Ticketfilter;

use CommonDropdown;
use DBConnection;
use Migration;
Expand Down Expand Up @@ -66,6 +67,7 @@ class FilterPattern extends CommonDropdown
const SUPPRESNOTIF = 'SuppressNotification';

/**
* getTypeName(int nb) : string -
* Method called by pre_item_add hook validates the object and passes
* it to the RegEx Matching then decides what to do.
*
Expand All @@ -82,6 +84,7 @@ static function getTypeName($nb = 0) : string


/**
* getMenuContent() : array | bool -
* Method called by pre_item_add hook validates the object and passes
* it to the RegEx Matching then decides what to do.
*
Expand All @@ -102,6 +105,7 @@ public static function getMenuContent()
}

/**
* getIcon() : string -
* Sets icon for object.
*
* @return string $icon
Expand All @@ -112,6 +116,7 @@ public static function getIcon() : string
}

/**
* getAdditionalFields() : array -
* Fetch fields for Dropdown 'add' form. Array order is equal with
* field order in the form
*
Expand Down Expand Up @@ -201,6 +206,7 @@ public function getAdditionalFields()
}

/**
* rawSearchOptions() : array -
* Add fields to search and potential table columns
*
* @return array $rawSearchOptions
Expand Down Expand Up @@ -262,13 +268,11 @@ public function rawSearchOptions() : array
}

/**
* getFilterPatterns() : array -
* Get match patterns and config from dropdowns
*
* @return patterns Array with all configured patterns
* @since 1.1.0
* @todo Figure out if there isnt an method in the dropdown object
* that allows us to retrieve the reference table contents in
* one itteration.
*/
public static function getFilterPatterns() : array
{
Expand Down Expand Up @@ -297,6 +301,7 @@ public static function getFilterPatterns() : array
}

/**
* install(Migration migration) : void -
* Install table needed for Ticket Filter configuration dropdowns
*
* @return void
Expand Down Expand Up @@ -352,6 +357,7 @@ public static function install(Migration $migration) : void
}

/**
* uninstall(Migration migration) : void -
* Uninstall tables uncomment the line to make plugin clean table.
*
* @return void
Expand Down
Loading

0 comments on commit 36e1ecb

Please sign in to comment.