| 1 |
<?php |
| 2 |
namespace FluentSupport\App\Http\Controllers; |
| 3 |
|
| 4 |
use FluentSupport\App\Services\Helper; |
| 5 |
use FluentSupport\App\Services\Tickets\Importer\MigratorService; |
| 6 |
use FluentSupport\Framework\Http\Request\Request; |
| 7 |
use FluentSupport\App\Services\Tickets\Importer\BaseImporter; |
| 8 |
|
| 9 |
|
| 10 |
class TicketImportController extends Controller |
| 11 |
{ |
| 12 |
public function getStats ( MigratorService $importService ) |
| 13 |
{ |
| 14 |
$stats = $importService->getStats(); |
| 15 |
if(!$stats) { |
| 16 |
return []; |
| 17 |
} |
| 18 |
return $stats; |
| 19 |
} |
| 20 |
|
| 21 |
public function importTickets(MigratorService $importService, Request $request) |
| 22 |
{ |
| 23 |
try { |
| 24 |
$handler = $request->getSafe('handler', 'sanitize_key'); |
| 25 |
$rawQuery = $request->get('query', []); |
| 26 |
$query = []; |
| 27 |
|
| 28 |
if (is_array($rawQuery)) { |
| 29 |
if (isset($rawQuery['access_token'])) { |
| 30 |
$query['access_token'] = sanitize_text_field($rawQuery['access_token']); |
| 31 |
} |
| 32 |
if (isset($rawQuery['mailbox'])) { |
| 33 |
$query['mailbox'] = intval($rawQuery['mailbox']); |
| 34 |
} |
| 35 |
if (isset($rawQuery['domain'])) { |
| 36 |
$query['domain'] = sanitize_text_field($rawQuery['domain']); |
| 37 |
} |
| 38 |
if (isset($rawQuery['email'])) { |
| 39 |
$query['email'] = sanitize_email($rawQuery['email']); |
| 40 |
} |
| 41 |
if (isset($rawQuery['cursor'])) { |
| 42 |
$query['cursor'] = sanitize_text_field($rawQuery['cursor']); |
| 43 |
} |
| 44 |
if (!empty($rawQuery['include_archived'])) { |
| 45 |
$query['include_archived'] = true; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
return $importService->handleImport( $request->getSafe('page', 'intval'), $handler, $query ); |
| 50 |
} catch (\Exception $e) { |
| 51 |
return $this->sendError(Helper::getSafeErrorMessage($e)); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
public function deleteTickets (MigratorService $importService, Request $request) |
| 56 |
{ |
| 57 |
return $importService->deleteTickets($request->getSafe('page', 'intval'), $request->getSafe('handler', 'sanitize_key')); |
| 58 |
} |
| 59 |
} |
| 60 |
|