-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathUpdateActivityItemsDescriptionSeeder.php
75 lines (58 loc) · 2.24 KB
/
UpdateActivityItemsDescriptionSeeder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class UpdateActivityItemsDescriptionSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$activityItems = [];
$activityItemsDescriptions = [];
if (file_exists(public_path('sample/activity-items-description.csv'))) {
$file = fopen(public_path('sample/activity-items-description.csv'), 'r');
$index = 0;
while (($line = fgetcsv($file)) !== FALSE) {
if ($line[0]!== '' && $line[1]!== '') {
$activityItems[$index] = strtolower(trim($line[0]));
$activityItemsDescriptions[$index] = trim($line[1]);
$index++;
}
}
fclose($file);
} else {
exit();
}
$allActivityItems = DB::table('activity_items')->select('id', 'title')->get();
foreach ($allActivityItems as $activityItem) {
$description = '';
$foundedKey = array_search(strtolower($activityItem->title), $activityItems);
if ($foundedKey) {
$description = $activityItemsDescriptions[$foundedKey];
DB::table('activity_items')
->where('id', $activityItem->id)
->update([
'description' => $description
]);
}
}
// update descriptions for layouts
$allActivityLayouts = DB::table('activity_layouts')->select('id', 'title')->get();
foreach ($allActivityLayouts as $activityLayout) {
$description = '';
$foundedKey = array_search(strtolower($activityLayout->title), $activityItems);
if ($foundedKey) {
$description = $activityItemsDescriptions[$foundedKey];
DB::table('activity_layouts')
->where('id', $activityLayout->id)
->update([
'description' => $description
]);
}
}
}
}