| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Services\Tickets\Importer; |
| 4 |
|
| 5 |
class MigratorService |
| 6 |
{ |
| 7 |
/** |
| 8 |
* This `getStats` method will fetch available other systems data |
| 9 |
*/ |
| 10 |
public function getStats() |
| 11 |
{ |
| 12 |
$stats = []; |
| 13 |
|
| 14 |
if (defined('WPAS_VERSION')) { |
| 15 |
$stats[] = $this->mapClassWithHandler('awesome-support')->stats(); |
| 16 |
} |
| 17 |
|
| 18 |
if (defined('WPSC_VERSION')) { |
| 19 |
$stats[] = $this->mapClassWithHandler('support-candy')->stats(); |
| 20 |
} |
| 21 |
|
| 22 |
if (defined('JSST_PLUGIN_PATH')) { |
| 23 |
$stats[] = $this->mapClassWithHandler('js-helpdesk')->stats(); |
| 24 |
} |
| 25 |
|
| 26 |
$stats[] = $this->mapClassWithHandler('helpscout')->stats(); |
| 27 |
$stats[] = $this->mapClassWithHandler('freshdesk')->stats(); |
| 28 |
$stats[] = $this->mapClassWithHandler('zendesk')->stats(); |
| 29 |
|
| 30 |
return [ |
| 31 |
'stats' => $stats |
| 32 |
]; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* This `handleImport` method will handle the ticket import |
| 37 |
* @param int $page // It can be page number or ticket id for inserting ticket |
| 38 |
* @param string $handler |
| 39 |
*/ |
| 40 |
public function handleImport($page, $handler, $query=[]) |
| 41 |
{ |
| 42 |
if($query){ |
| 43 |
$class = $this->mapClassWithHandler($handler); |
| 44 |
$class->setAccessToken($query['access_token']); |
| 45 |
isset($query['mailbox']) ? $class->setMailboxId($query['mailbox']) : ''; |
| 46 |
isset($query['domain']) ? $class->setDomain($query['domain']) : ''; |
| 47 |
isset($query['email']) ? $class->setEmail($query['email']) : ''; |
| 48 |
|
| 49 |
return $class->doMigration($page, $handler); |
| 50 |
} |
| 51 |
|
| 52 |
return $this->mapClassWithHandler($handler)->doMigration($page, $handler); |
| 53 |
} |
| 54 |
|
| 55 |
public function deleteTickets($page, $handler) |
| 56 |
{ |
| 57 |
return $this->mapClassWithHandler($handler)->deleteTickets($page); |
| 58 |
} |
| 59 |
|
| 60 |
// This method is a helper method of `handleImport` method it's responsible for calling a class by $handler |
| 61 |
private function mapClassWithHandler($handler) |
| 62 |
{ |
| 63 |
$namespace = "FluentSupport\App\Services\Tickets\Importer\\"; |
| 64 |
|
| 65 |
$classMapper = apply_filters('fluent_support/migrator_class_mapper', [ |
| 66 |
'awesome-support' => 'AwesomeSupportTickets', |
| 67 |
'support-candy' => 'SupportCandyTickets', |
| 68 |
'js-helpdesk' => 'JSHelpdeskTickets', |
| 69 |
'helpscout' => 'HelpScoutTickets', |
| 70 |
'freshdesk' => 'FreshDeskTickets', |
| 71 |
'zendesk' => 'ZendeskTickets' |
| 72 |
]); |
| 73 |
|
| 74 |
$class = $namespace . $classMapper[$handler]; |
| 75 |
|
| 76 |
return new $class(); |
| 77 |
} |
| 78 |
} |
| 79 |
|