|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use App\User; |
|
6
|
|
|
use Illuminate\Console\Command; |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
use PDOException; |
|
9
|
|
|
use Scriptotek\Alma\Client as AlmaClient; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class SyncUsers extends Command |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The name and signature of the console command. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $signature = 'bibrex:sync-users'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The console command description. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $description = 'Sync all users'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Create a new command instance. |
|
29
|
|
|
* |
|
30
|
|
|
* @param AlmaClient $alma |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(AlmaClient $alma) |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct(); |
|
35
|
|
|
$this->alma = $alma; |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Update a single user |
|
40
|
|
|
* |
|
41
|
|
|
* @param User $user |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function processUser(User $user) |
|
44
|
|
|
{ |
|
45
|
|
|
echo " - $user->name: "; |
|
46
|
|
|
|
|
47
|
|
|
if ($user->in_alma) { |
|
48
|
|
|
if ($user->updateFromAlma($this->alma)) { |
|
49
|
|
|
if ($user->isDirty()) { |
|
50
|
|
|
\Log::info(sprintf( |
|
51
|
|
|
'Oppdaterte brukeren <a href="%s">%s</a> fra Alma.', |
|
52
|
|
|
action('UsersController@getShow', $user->id), |
|
|
|
|
|
|
53
|
|
|
$user->name |
|
54
|
|
|
)); |
|
55
|
|
|
|
|
56
|
|
|
$this->info('oppdatert'); |
|
57
|
|
|
} else { |
|
58
|
|
|
$this->line('ingen endringer'); |
|
59
|
|
|
} |
|
60
|
|
|
} else { |
|
61
|
|
|
\Log::info(sprintf( |
|
62
|
|
|
'Brukeren <a href="%s">%s</a> ble ikke lenger funnet i Alma!', |
|
63
|
|
|
action('UsersController@getShow', $user->id), |
|
64
|
|
|
$user->name |
|
65
|
|
|
)); |
|
66
|
|
|
|
|
67
|
|
|
$this->warn('ikke i Alma lenger'); |
|
68
|
|
|
} |
|
69
|
|
|
} else { |
|
70
|
|
|
if ($user->updateFromAlma($this->alma)) { |
|
71
|
|
|
\Log::info(sprintf( |
|
72
|
|
|
'Lenket brukeren <a href="%s">%s</a> til en Alma-bruker.', |
|
73
|
|
|
action('UsersController@getShow', $user->id), |
|
74
|
|
|
$user->name |
|
75
|
|
|
)); |
|
76
|
|
|
|
|
77
|
|
|
$this->info('lenket til Alma-bruker'); |
|
78
|
|
|
} else { |
|
79
|
|
|
$this->line('ikke i Alma'); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
try { |
|
83
|
|
|
$user->save(); |
|
84
|
|
|
} catch (PDOException $e) { |
|
85
|
|
|
$this->error('Konflikt!'); |
|
86
|
|
|
\Log::info(sprintf( |
|
87
|
|
|
'Brukeren <a href="%s">%s</a> kunne ikke lagres på grunn av en konflikt - to brukere har ' . |
|
88
|
|
|
'samme strekkode eller feide-id. Sjekk i brukerlista om det er to brukere som kan slås sammen.', |
|
89
|
|
|
action('UsersController@getShow', $user->id), |
|
90
|
|
|
$user->name |
|
91
|
|
|
)); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Execute the console command. |
|
97
|
|
|
* |
|
98
|
|
|
* @return mixed |
|
99
|
|
|
*/ |
|
100
|
|
|
public function handle() |
|
101
|
|
|
{ |
|
102
|
|
|
foreach (User::get() as $user) { |
|
103
|
|
|
$this->processUser($user); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths