PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.10.2
Fluent Support – Helpdesk & Customer Support Ticket System v1.10.2
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Services / Tickets / Importer / Common.php

Common.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.10.2, at app/Services/Tickets/Importer/Common.php

67 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Services\Tickets\Importer;
4
5 use FluentSupport\App\Models\Person;
6
7 class Common
8 {
9 public static function updateOrCreatePerson($personData)
10 {
11 $emailArray = [
12 'email' => $personData['email'],
13 'person_type' => $personData['person_type']
14 ];
15
16 $person = Person::updateOrCreate($emailArray, $personData);
17 return $person->toArray();
18 }
19
20 public static function formatPersonData($personData, $type)
21 {
22 if(!$personData) {
23 return [];
24 }
25
26 $name = explode(' ', $personData->name);
27
28 return [
29 'first_name' => $name[0] ?? '',
30 'last_name' => $name[1] ?? '',
31 'email' => $personData->email ?? $personData->address,
32 'person_type' => $type
33 ];
34 }
35
36 // Download a file from a remote URL and create a new directory for this if not exists
37 // Then save the file to the new directory and move this directory to a new given directory
38 public static function downloadFile($remoteUrl, $baseDir, $fileName)
39 {
40 $filePath = $baseDir . $fileName;
41
42 if (!file_exists($baseDir)) {
43 mkdir($baseDir, 0777, true);
44 }
45
46 if (!file_exists($filePath)) {
47 $response = wp_remote_get($remoteUrl, [
48 'timeout' => 60,
49 'stream' => false
50 ]);
51
52 if (is_wp_error($response)) {
53 return false;
54 }
55
56 $file_contents = wp_remote_retrieve_body($response);
57 if (empty($file_contents)) {
58 return false;
59 }
60
61 file_put_contents($filePath, $file_contents);
62 }
63
64 return $filePath;
65 }
66 }
67