Passed
Branch feature/2.0 (9789a8)
by Jonathan
14:17
created
src/Webtrees/Module/AdminTasks/Schema/Migration1.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -25,25 +25,25 @@
 block discarded – undo
25 25
 class Migration1 implements MigrationInterface
26 26
 {
27 27
 
28
-    /**
29
-     * {@inheritDoc}
30
-     * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
31
-     */
32
-    public function upgrade(): void
33
-    {
34
-        // Clean up previous admin tasks table if it exists
35
-        DB::schema()->dropIfExists('maj_admintasks');
36
-
37
-        DB::schema()->create('maj_admintasks', static function (Blueprint $table): void {
38
-
39
-            $table->increments('majat_id');
40
-            $table->string('majat_task_id', 32)->unique();
41
-            $table->enum('majat_status', ['enabled', 'disabled'])->default('disabled');
42
-            $table->dateTime('majat_last_run')->default(Carbon::createFromTimestampUTC(0));
43
-            $table->boolean('majat_last_result')->default(true);
44
-            $table->integer('majat_frequency')->default(10080);
45
-            $table->smallInteger('majat_nb_occur')->default(0);
46
-            $table->boolean('majat_running')->default(false);
47
-        });
48
-    }
28
+	/**
29
+	 * {@inheritDoc}
30
+	 * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
31
+	 */
32
+	public function upgrade(): void
33
+	{
34
+		// Clean up previous admin tasks table if it exists
35
+		DB::schema()->dropIfExists('maj_admintasks');
36
+
37
+		DB::schema()->create('maj_admintasks', static function (Blueprint $table): void {
38
+
39
+			$table->increments('majat_id');
40
+			$table->string('majat_task_id', 32)->unique();
41
+			$table->enum('majat_status', ['enabled', 'disabled'])->default('disabled');
42
+			$table->dateTime('majat_last_run')->default(Carbon::createFromTimestampUTC(0));
43
+			$table->boolean('majat_last_result')->default(true);
44
+			$table->integer('majat_frequency')->default(10080);
45
+			$table->smallInteger('majat_nb_occur')->default(0);
46
+			$table->boolean('majat_running')->default(false);
47
+		});
48
+	}
49 49
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
         // Clean up previous admin tasks table if it exists
35 35
         DB::schema()->dropIfExists('maj_admintasks');
36 36
 
37
-        DB::schema()->create('maj_admintasks', static function (Blueprint $table): void {
37
+        DB::schema()->create('maj_admintasks', static function(Blueprint $table): void {
38 38
 
39 39
             $table->increments('majat_id');
40 40
             $table->string('majat_task_id', 32)->unique();
Please login to merge, or discard this patch.
src/Webtrees/Module/AdminTasks/Services/TaskScheduleService.php 2 patches
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -33,253 +33,253 @@
 block discarded – undo
33 33
  */
34 34
 class TaskScheduleService
35 35
 {
36
-    /**
37
-     * Time-out after which the task will be considered not running any more.
38
-     * In seconds, default 5 mins.
39
-     * @var integer
40
-     */
41
-    public const TASK_TIME_OUT = 600;
42
-
43
-    /**
44
-     * @var Collection $available_tasks
45
-     */
46
-    private $available_tasks;
47
-
48
-    /**
49
-     * Returns all Tasks schedules in database.
50
-     * Stored records can be synchronised with the tasks actually available to the system.
51
-     *
52
-     * @param bool $sync_available Should tasks synchronised with available ones
53
-     * @param bool $include_disabled Should disabled tasks be returned
54
-     * @return Collection Collection of TaskSchedule
55
-     */
56
-    public function all(bool $sync_available = false, bool $include_disabled = true): Collection
57
-    {
58
-        $tasks_schedules = DB::table('maj_admintasks')
59
-        ->select()
60
-        ->get()
61
-        ->map(self::rowMapper());
62
-
63
-        if ($sync_available) {
64
-            $available_tasks = clone $this->available();
65
-            foreach ($tasks_schedules as $task_schedule) {
66
-                /** @var TaskSchedule $task_schedule */
67
-                if ($available_tasks->has($task_schedule->taskId())) {
68
-                    $available_tasks->forget($task_schedule->taskId());
69
-                } else {
70
-                    $this->delete($task_schedule);
71
-                }
72
-            }
73
-
74
-            foreach ($available_tasks as $task_name => $task) {
75
-                /** @var TaskInterface $task */
76
-                $this->insertTask($task_name, $task->defaultFrequency());
77
-            }
78
-
79
-            return $this->all(false, $include_disabled);
80
-        }
81
-
82
-        return $tasks_schedules;
83
-    }
84
-
85
-    /**
86
-     * Returns tasks exposed through modules implementing ModuleTasksProviderInterface.
87
-     *
88
-     * @return Collection
89
-     */
90
-    public function available(): Collection
91
-    {
92
-        if ($this->available_tasks === null) {
93
-            $tasks_providers = app(ModuleService::class)->findByInterface(ModuleTasksProviderInterface::class);
94
-
95
-            $this->available_tasks = new Collection();
96
-            foreach ($tasks_providers as $task_provider) {
97
-                $this->available_tasks = $this->available_tasks->merge($task_provider->listTasks());
98
-            }
99
-        }
100
-        return $this->available_tasks;
101
-    }
102
-
103
-    /**
104
-     * Find a task schedule by its ID.
105
-     *
106
-     * @param int $task_schedule_id
107
-     * @return TaskSchedule|NULL
108
-     */
109
-    public function find(int $task_schedule_id): ?TaskSchedule
110
-    {
111
-        return DB::table('maj_admintasks')
112
-            ->select()
113
-            ->where('majat_id', '=', $task_schedule_id)
114
-            ->get()
115
-            ->map(self::rowMapper())
116
-            ->first();
117
-    }
118
-
119
-    /**
120
-     * Add a new task schedule with the specified task ID, and frequency if defined.
121
-     * Uses default for other settings.
122
-     *
123
-     * @param string $task_id
124
-     * @param int $frequency
125
-     * @return bool
126
-     */
127
-    public function insertTask(string $task_id, int $frequency = 0): bool
128
-    {
129
-        $values = ['majat_task_id' => $task_id];
130
-        if ($frequency > 0) {
131
-            $values['majat_frequency'] = $frequency;
132
-        }
133
-
134
-        return DB::table('maj_admintasks')
135
-            ->insert($values);
136
-    }
137
-
138
-    /**
139
-     * Update a task schedule.
140
-     * Returns the number of tasks schedules updated.
141
-     *
142
-     * @param TaskSchedule $task_schedule
143
-     * @return int
144
-     */
145
-    public function update(TaskSchedule $task_schedule): int
146
-    {
147
-        return DB::table('maj_admintasks')
148
-            ->where('majat_id', '=', $task_schedule->id())
149
-            ->update([
150
-                'majat_status'      =>  $task_schedule->isEnabled() ? 'enabled' : 'disabled',
151
-                'majat_last_run'    =>  $task_schedule->lastRunTime(),
152
-                'majat_last_result' =>  $task_schedule->wasLastRunSuccess(),
153
-                'majat_frequency'   =>  $task_schedule->frequency()->totalMinutes,
154
-                'majat_nb_occur'    =>  $task_schedule->remainingOccurences(),
155
-                'majat_running'     =>  $task_schedule->isRunning()
156
-            ]);
157
-    }
158
-
159
-    /**
160
-     * Delete a task schedule.
161
-     *
162
-     * @param TaskSchedule $task_schedule
163
-     * @return int
164
-     */
165
-    public function delete(TaskSchedule $task_schedule): int
166
-    {
167
-        return DB::table('maj_admintasks')
168
-            ->where('majat_id', '=', $task_schedule->id())
169
-            ->delete();
170
-    }
171
-
172
-    /**
173
-     * Find a task by its name
174
-     *
175
-     * @param string $task_id
176
-     * @return TaskInterface|NULL
177
-     */
178
-    public function findTask(string $task_id): ?TaskInterface
179
-    {
180
-        if ($this->available()->has($task_id)) {
181
-            return app($this->available()->get($task_id));
182
-        }
183
-        return null;
184
-    }
185
-
186
-    /**
187
-     * Retrieve all tasks that are candidates to be run.
188
-     *
189
-     * @param bool $force Should the run be forced
190
-     * @param string $task_id Specific task ID to be run
191
-     * @return Collection
192
-     */
193
-    public function findTasksToRun(bool $force, string $task_id = null): Collection
194
-    {
195
-        $query = DB::table('maj_admintasks')
196
-            ->select()
197
-            ->where('majat_status', '=', 'enabled')
198
-            ->where(function (Builder $query): void {
199
-
200
-                $query->where('majat_running', '=', 0)
201
-                ->orWhere('majat_last_run', '<=', Carbon::now()->subSeconds(self::TASK_TIME_OUT));
202
-            });
203
-
204
-        if (!$force) {
205
-            $query->where(function (Builder $query): void {
206
-
207
-                $query->where('majat_running', '=', 0)
208
-                    ->orWhereRaw('DATE_ADD(majat_last_run, INTERVAL majat_frequency MINUTE) <= NOW()');
209
-            });
210
-        }
211
-
212
-        if ($task_id !== null) {
213
-            $query->where('majat_task_id', '=', $task_id);
214
-        }
215
-
216
-        return $query->get()->map(self::rowMapper());
217
-    }
218
-
219
-    /**
220
-     * Run the task associated with the schedule.
221
-     * The task will run if either forced to, or its next scheduled run time has been exceeded.
222
-     * The last run time is recorded only if the task is successful.
223
-     *
224
-     * @param TaskSchedule $task_schedule
225
-     * @param boolean $force
226
-     */
227
-    public function run(TaskSchedule $task_schedule, $force = false): void
228
-    {
229
-        /** @var TaskSchedule $task_schedule */
230
-        $task_schedule = DB::table('maj_admintasks')
231
-            ->select()
232
-            ->where('majat_id', '=', $task_schedule->id())
233
-            ->lockForUpdate()
234
-            ->get()
235
-            ->map(self::rowMapper())
236
-            ->first();
237
-
238
-        if (
239
-            !$task_schedule->isRunning() &&
240
-            ($force || $task_schedule->lastRunTime()->add($task_schedule->frequency())->lessThan(Carbon::now()))
241
-        ) {
242
-            $task_schedule->setLastResult(false);
243
-
244
-            $task = $this->findTask($task_schedule->taskId());
245
-            if ($task !== null) {
246
-                $task_schedule->startRunning();
247
-                $this->update($task_schedule);
248
-
249
-                try {
250
-                    $task_schedule->setLastResult($task->run($task_schedule));
251
-                } catch (Exception $ex) {
252
-                }
253
-
254
-                if ($task_schedule->wasLastRunSuccess()) {
255
-                    $task_schedule->setLastRunTime(Carbon::now());
256
-                    $task_schedule->decrementRemainingOccurences();
257
-                }
258
-                $task_schedule->stopRunning();
259
-            }
260
-            $this->update($task_schedule);
261
-        }
262
-    }
263
-
264
-    /**
265
-     * Mapper to return a TaskSchedule object from an object.
266
-     *
267
-     * @return Closure
268
-     */
269
-    public static function rowMapper(): Closure
270
-    {
271
-        return static function (stdClass $row): TaskSchedule {
272
-
273
-            return new TaskSchedule(
274
-                (int) $row->majat_id,
275
-                $row->majat_task_id,
276
-                $row->majat_status === 'enabled',
277
-                Carbon::parse($row->majat_last_run),
278
-                (bool) $row->majat_last_result,
279
-                CarbonInterval::minutes($row->majat_frequency),
280
-                (int) $row->majat_nb_occur,
281
-                (bool) $row->majat_running
282
-            );
283
-        };
284
-    }
36
+	/**
37
+	 * Time-out after which the task will be considered not running any more.
38
+	 * In seconds, default 5 mins.
39
+	 * @var integer
40
+	 */
41
+	public const TASK_TIME_OUT = 600;
42
+
43
+	/**
44
+	 * @var Collection $available_tasks
45
+	 */
46
+	private $available_tasks;
47
+
48
+	/**
49
+	 * Returns all Tasks schedules in database.
50
+	 * Stored records can be synchronised with the tasks actually available to the system.
51
+	 *
52
+	 * @param bool $sync_available Should tasks synchronised with available ones
53
+	 * @param bool $include_disabled Should disabled tasks be returned
54
+	 * @return Collection Collection of TaskSchedule
55
+	 */
56
+	public function all(bool $sync_available = false, bool $include_disabled = true): Collection
57
+	{
58
+		$tasks_schedules = DB::table('maj_admintasks')
59
+		->select()
60
+		->get()
61
+		->map(self::rowMapper());
62
+
63
+		if ($sync_available) {
64
+			$available_tasks = clone $this->available();
65
+			foreach ($tasks_schedules as $task_schedule) {
66
+				/** @var TaskSchedule $task_schedule */
67
+				if ($available_tasks->has($task_schedule->taskId())) {
68
+					$available_tasks->forget($task_schedule->taskId());
69
+				} else {
70
+					$this->delete($task_schedule);
71
+				}
72
+			}
73
+
74
+			foreach ($available_tasks as $task_name => $task) {
75
+				/** @var TaskInterface $task */
76
+				$this->insertTask($task_name, $task->defaultFrequency());
77
+			}
78
+
79
+			return $this->all(false, $include_disabled);
80
+		}
81
+
82
+		return $tasks_schedules;
83
+	}
84
+
85
+	/**
86
+	 * Returns tasks exposed through modules implementing ModuleTasksProviderInterface.
87
+	 *
88
+	 * @return Collection
89
+	 */
90
+	public function available(): Collection
91
+	{
92
+		if ($this->available_tasks === null) {
93
+			$tasks_providers = app(ModuleService::class)->findByInterface(ModuleTasksProviderInterface::class);
94
+
95
+			$this->available_tasks = new Collection();
96
+			foreach ($tasks_providers as $task_provider) {
97
+				$this->available_tasks = $this->available_tasks->merge($task_provider->listTasks());
98
+			}
99
+		}
100
+		return $this->available_tasks;
101
+	}
102
+
103
+	/**
104
+	 * Find a task schedule by its ID.
105
+	 *
106
+	 * @param int $task_schedule_id
107
+	 * @return TaskSchedule|NULL
108
+	 */
109
+	public function find(int $task_schedule_id): ?TaskSchedule
110
+	{
111
+		return DB::table('maj_admintasks')
112
+			->select()
113
+			->where('majat_id', '=', $task_schedule_id)
114
+			->get()
115
+			->map(self::rowMapper())
116
+			->first();
117
+	}
118
+
119
+	/**
120
+	 * Add a new task schedule with the specified task ID, and frequency if defined.
121
+	 * Uses default for other settings.
122
+	 *
123
+	 * @param string $task_id
124
+	 * @param int $frequency
125
+	 * @return bool
126
+	 */
127
+	public function insertTask(string $task_id, int $frequency = 0): bool
128
+	{
129
+		$values = ['majat_task_id' => $task_id];
130
+		if ($frequency > 0) {
131
+			$values['majat_frequency'] = $frequency;
132
+		}
133
+
134
+		return DB::table('maj_admintasks')
135
+			->insert($values);
136
+	}
137
+
138
+	/**
139
+	 * Update a task schedule.
140
+	 * Returns the number of tasks schedules updated.
141
+	 *
142
+	 * @param TaskSchedule $task_schedule
143
+	 * @return int
144
+	 */
145
+	public function update(TaskSchedule $task_schedule): int
146
+	{
147
+		return DB::table('maj_admintasks')
148
+			->where('majat_id', '=', $task_schedule->id())
149
+			->update([
150
+				'majat_status'      =>  $task_schedule->isEnabled() ? 'enabled' : 'disabled',
151
+				'majat_last_run'    =>  $task_schedule->lastRunTime(),
152
+				'majat_last_result' =>  $task_schedule->wasLastRunSuccess(),
153
+				'majat_frequency'   =>  $task_schedule->frequency()->totalMinutes,
154
+				'majat_nb_occur'    =>  $task_schedule->remainingOccurences(),
155
+				'majat_running'     =>  $task_schedule->isRunning()
156
+			]);
157
+	}
158
+
159
+	/**
160
+	 * Delete a task schedule.
161
+	 *
162
+	 * @param TaskSchedule $task_schedule
163
+	 * @return int
164
+	 */
165
+	public function delete(TaskSchedule $task_schedule): int
166
+	{
167
+		return DB::table('maj_admintasks')
168
+			->where('majat_id', '=', $task_schedule->id())
169
+			->delete();
170
+	}
171
+
172
+	/**
173
+	 * Find a task by its name
174
+	 *
175
+	 * @param string $task_id
176
+	 * @return TaskInterface|NULL
177
+	 */
178
+	public function findTask(string $task_id): ?TaskInterface
179
+	{
180
+		if ($this->available()->has($task_id)) {
181
+			return app($this->available()->get($task_id));
182
+		}
183
+		return null;
184
+	}
185
+
186
+	/**
187
+	 * Retrieve all tasks that are candidates to be run.
188
+	 *
189
+	 * @param bool $force Should the run be forced
190
+	 * @param string $task_id Specific task ID to be run
191
+	 * @return Collection
192
+	 */
193
+	public function findTasksToRun(bool $force, string $task_id = null): Collection
194
+	{
195
+		$query = DB::table('maj_admintasks')
196
+			->select()
197
+			->where('majat_status', '=', 'enabled')
198
+			->where(function (Builder $query): void {
199
+
200
+				$query->where('majat_running', '=', 0)
201
+				->orWhere('majat_last_run', '<=', Carbon::now()->subSeconds(self::TASK_TIME_OUT));
202
+			});
203
+
204
+		if (!$force) {
205
+			$query->where(function (Builder $query): void {
206
+
207
+				$query->where('majat_running', '=', 0)
208
+					->orWhereRaw('DATE_ADD(majat_last_run, INTERVAL majat_frequency MINUTE) <= NOW()');
209
+			});
210
+		}
211
+
212
+		if ($task_id !== null) {
213
+			$query->where('majat_task_id', '=', $task_id);
214
+		}
215
+
216
+		return $query->get()->map(self::rowMapper());
217
+	}
218
+
219
+	/**
220
+	 * Run the task associated with the schedule.
221
+	 * The task will run if either forced to, or its next scheduled run time has been exceeded.
222
+	 * The last run time is recorded only if the task is successful.
223
+	 *
224
+	 * @param TaskSchedule $task_schedule
225
+	 * @param boolean $force
226
+	 */
227
+	public function run(TaskSchedule $task_schedule, $force = false): void
228
+	{
229
+		/** @var TaskSchedule $task_schedule */
230
+		$task_schedule = DB::table('maj_admintasks')
231
+			->select()
232
+			->where('majat_id', '=', $task_schedule->id())
233
+			->lockForUpdate()
234
+			->get()
235
+			->map(self::rowMapper())
236
+			->first();
237
+
238
+		if (
239
+			!$task_schedule->isRunning() &&
240
+			($force || $task_schedule->lastRunTime()->add($task_schedule->frequency())->lessThan(Carbon::now()))
241
+		) {
242
+			$task_schedule->setLastResult(false);
243
+
244
+			$task = $this->findTask($task_schedule->taskId());
245
+			if ($task !== null) {
246
+				$task_schedule->startRunning();
247
+				$this->update($task_schedule);
248
+
249
+				try {
250
+					$task_schedule->setLastResult($task->run($task_schedule));
251
+				} catch (Exception $ex) {
252
+				}
253
+
254
+				if ($task_schedule->wasLastRunSuccess()) {
255
+					$task_schedule->setLastRunTime(Carbon::now());
256
+					$task_schedule->decrementRemainingOccurences();
257
+				}
258
+				$task_schedule->stopRunning();
259
+			}
260
+			$this->update($task_schedule);
261
+		}
262
+	}
263
+
264
+	/**
265
+	 * Mapper to return a TaskSchedule object from an object.
266
+	 *
267
+	 * @return Closure
268
+	 */
269
+	public static function rowMapper(): Closure
270
+	{
271
+		return static function (stdClass $row): TaskSchedule {
272
+
273
+			return new TaskSchedule(
274
+				(int) $row->majat_id,
275
+				$row->majat_task_id,
276
+				$row->majat_status === 'enabled',
277
+				Carbon::parse($row->majat_last_run),
278
+				(bool) $row->majat_last_result,
279
+				CarbonInterval::minutes($row->majat_frequency),
280
+				(int) $row->majat_nb_occur,
281
+				(bool) $row->majat_running
282
+			);
283
+		};
284
+	}
285 285
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -195,14 +195,14 @@  discard block
 block discarded – undo
195 195
         $query = DB::table('maj_admintasks')
196 196
             ->select()
197 197
             ->where('majat_status', '=', 'enabled')
198
-            ->where(function (Builder $query): void {
198
+            ->where(function(Builder $query): void {
199 199
 
200 200
                 $query->where('majat_running', '=', 0)
201 201
                 ->orWhere('majat_last_run', '<=', Carbon::now()->subSeconds(self::TASK_TIME_OUT));
202 202
             });
203 203
 
204 204
         if (!$force) {
205
-            $query->where(function (Builder $query): void {
205
+            $query->where(function(Builder $query): void {
206 206
 
207 207
                 $query->where('majat_running', '=', 0)
208 208
                     ->orWhereRaw('DATE_ADD(majat_last_run, INTERVAL majat_frequency MINUTE) <= NOW()');
@@ -268,17 +268,17 @@  discard block
 block discarded – undo
268 268
      */
269 269
     public static function rowMapper(): Closure
270 270
     {
271
-        return static function (stdClass $row): TaskSchedule {
271
+        return static function(stdClass $row): TaskSchedule {
272 272
 
273 273
             return new TaskSchedule(
274
-                (int) $row->majat_id,
274
+                (int)$row->majat_id,
275 275
                 $row->majat_task_id,
276 276
                 $row->majat_status === 'enabled',
277 277
                 Carbon::parse($row->majat_last_run),
278
-                (bool) $row->majat_last_result,
278
+                (bool)$row->majat_last_result,
279 279
                 CarbonInterval::minutes($row->majat_frequency),
280
-                (int) $row->majat_nb_occur,
281
-                (bool) $row->majat_running
280
+                (int)$row->majat_nb_occur,
281
+                (bool)$row->majat_running
282 282
             );
283 283
         };
284 284
     }
Please login to merge, or discard this patch.
src/Webtrees/Module/AdminTasks/Services/HealthCheckService.php 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -27,101 +27,101 @@
 block discarded – undo
27 27
  */
28 28
 class HealthCheckService
29 29
 {
30
-    /**
31
-     * Returns a query collating all gedcom records, for use in other queries
32
-     *
33
-     * @param Tree $tree
34
-     * @return Builder
35
-     */
36
-    private function allGedcomRecords(Tree $tree): Builder
37
-    {
38
-        return DB::table('individuals')
39
-            ->select(DB::raw("'indi' AS ged_type"), 'i_id AS ged_id')->where('i_file', '=', $tree->id())
40
-            ->unionAll(DB::table('families')
41
-                ->select(DB::raw("'fam' AS ged_type"), 'f_id AS ged_id')->where('f_file', '=', $tree->id()))
42
-            ->unionAll(DB::table('sources')
43
-                ->select(DB::raw("'sour' AS ged_type"), 's_id AS ged_id')->where('s_file', '=', $tree->id()))
44
-            ->unionAll(DB::table('media')
45
-                ->select(DB::raw("'media' AS ged_type"), 'm_id AS ged_id')->where('m_file', '=', $tree->id()))
46
-            ->unionAll(DB::table('other')
47
-                ->select(DB::raw('LOWER(o_type) AS ged_type'), 'o_id AS ged_id')->where('o_file', '=', $tree->id()));
48
-    }
30
+	/**
31
+	 * Returns a query collating all gedcom records, for use in other queries
32
+	 *
33
+	 * @param Tree $tree
34
+	 * @return Builder
35
+	 */
36
+	private function allGedcomRecords(Tree $tree): Builder
37
+	{
38
+		return DB::table('individuals')
39
+			->select(DB::raw("'indi' AS ged_type"), 'i_id AS ged_id')->where('i_file', '=', $tree->id())
40
+			->unionAll(DB::table('families')
41
+				->select(DB::raw("'fam' AS ged_type"), 'f_id AS ged_id')->where('f_file', '=', $tree->id()))
42
+			->unionAll(DB::table('sources')
43
+				->select(DB::raw("'sour' AS ged_type"), 's_id AS ged_id')->where('s_file', '=', $tree->id()))
44
+			->unionAll(DB::table('media')
45
+				->select(DB::raw("'media' AS ged_type"), 'm_id AS ged_id')->where('m_file', '=', $tree->id()))
46
+			->unionAll(DB::table('other')
47
+				->select(DB::raw('LOWER(o_type) AS ged_type'), 'o_id AS ged_id')->where('o_file', '=', $tree->id()));
48
+	}
49 49
 
50
-    /**
51
-     * Returns the count of gedcom records by type in a Tree, as a keyed Collection.
52
-     *
53
-     * Collection output:
54
-     *      - Key : gedcom record type
55
-     *      - Value: count of records
56
-     *
57
-     * @param Tree $tree
58
-     * @return Collection
59
-     */
60
-    public function countByRecordType(Tree $tree): Collection
61
-    {
62
-        return DB::query()
63
-            ->fromSub($this->allGedcomRecords($tree), 'gedrecords')
64
-            ->select('ged_type', new Expression('COUNT(ged_id) AS total'))
65
-            ->groupBy('ged_type')
66
-            ->pluck('total', 'ged_type');
67
-    }
50
+	/**
51
+	 * Returns the count of gedcom records by type in a Tree, as a keyed Collection.
52
+	 *
53
+	 * Collection output:
54
+	 *      - Key : gedcom record type
55
+	 *      - Value: count of records
56
+	 *
57
+	 * @param Tree $tree
58
+	 * @return Collection
59
+	 */
60
+	public function countByRecordType(Tree $tree): Collection
61
+	{
62
+		return DB::query()
63
+			->fromSub($this->allGedcomRecords($tree), 'gedrecords')
64
+			->select('ged_type', new Expression('COUNT(ged_id) AS total'))
65
+			->groupBy('ged_type')
66
+			->pluck('total', 'ged_type');
67
+	}
68 68
 
69
-    /**
70
-     * Returns the count of gedcom records changes by type in a Tree across a number of days, as a keyed Collection.
71
-     *
72
-     * Collection output:
73
-     *      - Key : gedcom record type
74
-     *      - Value: count of changes
75
-     *
76
-     * @param Tree $tree
77
-     * @return Collection
78
-     */
79
-    public function changesByRecordType(Tree $tree, int $nb_days): Collection
80
-    {
81
-        return DB::table('change')
82
-            ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function (JoinClause $join) use ($tree): void {
69
+	/**
70
+	 * Returns the count of gedcom records changes by type in a Tree across a number of days, as a keyed Collection.
71
+	 *
72
+	 * Collection output:
73
+	 *      - Key : gedcom record type
74
+	 *      - Value: count of changes
75
+	 *
76
+	 * @param Tree $tree
77
+	 * @return Collection
78
+	 */
79
+	public function changesByRecordType(Tree $tree, int $nb_days): Collection
80
+	{
81
+		return DB::table('change')
82
+			->joinSub($this->allGedcomRecords($tree), 'gedrecords', function (JoinClause $join) use ($tree): void {
83 83
 
84
-                $join->on('change.xref', '=', 'gedrecords.ged_id')
85
-                    ->where('change.gedcom_id', '=', $tree->id());
86
-            })
87
-            ->select('ged_type AS type', new Expression('COUNT(change_id) AS count'))
88
-            ->where('change.status', '', 'accepted')
89
-            ->where('change.change_time', '>=', Carbon::now()->subDays($nb_days))
90
-            ->groupBy('ged_type')
91
-            ->pluck('total', 'ged_type');
92
-    }
84
+				$join->on('change.xref', '=', 'gedrecords.ged_id')
85
+					->where('change.gedcom_id', '=', $tree->id());
86
+			})
87
+			->select('ged_type AS type', new Expression('COUNT(change_id) AS count'))
88
+			->where('change.status', '', 'accepted')
89
+			->where('change.change_time', '>=', Carbon::now()->subDays($nb_days))
90
+			->groupBy('ged_type')
91
+			->pluck('total', 'ged_type');
92
+	}
93 93
 
94
-    /**
95
-     * Return the error logs associated with a tree across a number of days, grouped by error message, as a Collection.
96
-     *
97
-     * Collection output:
98
-     *      - Value: stdClass object
99
-     *          - log message:  Error log message
100
-     *          - type:         'site' if no associated Tree, the Tree ID otherwise
101
-     *          - nblogs:       The number of occurence of the same error message
102
-     *          - lastoccurred: Date/time of the last occurence of the error message
103
-     *
104
-     * @param Tree $tree
105
-     * @param int $nb_days
106
-     * @return Collection
107
-     */
108
-    public function errorLogs(Tree $tree, int $nb_days): Collection
109
-    {
110
-        return DB::table('log')
111
-            ->select(
112
-                'log_message',
113
-                new Expression("IFNULL(gedcom_id, 'site') as type"),
114
-                new Expression('COUNT(log_id) AS nblogs'),
115
-                new Expression('MAX(log_time) AS lastoccurred')
116
-            )
117
-            ->where('log_type', '=', 'error')
118
-            ->where(function (Builder $query) use ($tree): void {
119
-                $query->where('gedcom_id', '=', $tree->id())
120
-                    ->orWhereNull('gedcom_id');
121
-            })
122
-            ->where('log_time', '>=', Carbon::now()->subDays($nb_days))
123
-            ->groupBy('log_message', 'gedcom_id')
124
-            ->orderByDesc('lastoccurred')
125
-            ->get();
126
-    }
94
+	/**
95
+	 * Return the error logs associated with a tree across a number of days, grouped by error message, as a Collection.
96
+	 *
97
+	 * Collection output:
98
+	 *      - Value: stdClass object
99
+	 *          - log message:  Error log message
100
+	 *          - type:         'site' if no associated Tree, the Tree ID otherwise
101
+	 *          - nblogs:       The number of occurence of the same error message
102
+	 *          - lastoccurred: Date/time of the last occurence of the error message
103
+	 *
104
+	 * @param Tree $tree
105
+	 * @param int $nb_days
106
+	 * @return Collection
107
+	 */
108
+	public function errorLogs(Tree $tree, int $nb_days): Collection
109
+	{
110
+		return DB::table('log')
111
+			->select(
112
+				'log_message',
113
+				new Expression("IFNULL(gedcom_id, 'site') as type"),
114
+				new Expression('COUNT(log_id) AS nblogs'),
115
+				new Expression('MAX(log_time) AS lastoccurred')
116
+			)
117
+			->where('log_type', '=', 'error')
118
+			->where(function (Builder $query) use ($tree): void {
119
+				$query->where('gedcom_id', '=', $tree->id())
120
+					->orWhereNull('gedcom_id');
121
+			})
122
+			->where('log_time', '>=', Carbon::now()->subDays($nb_days))
123
+			->groupBy('log_message', 'gedcom_id')
124
+			->orderByDesc('lastoccurred')
125
+			->get();
126
+	}
127 127
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
     public function changesByRecordType(Tree $tree, int $nb_days): Collection
80 80
     {
81 81
         return DB::table('change')
82
-            ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function (JoinClause $join) use ($tree): void {
82
+            ->joinSub($this->allGedcomRecords($tree), 'gedrecords', function(JoinClause $join) use ($tree): void {
83 83
 
84 84
                 $join->on('change.xref', '=', 'gedrecords.ged_id')
85 85
                     ->where('change.gedcom_id', '=', $tree->id());
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                 new Expression('MAX(log_time) AS lastoccurred')
116 116
             )
117 117
             ->where('log_type', '=', 'error')
118
-            ->where(function (Builder $query) use ($tree): void {
118
+            ->where(function(Builder $query) use ($tree): void {
119 119
                 $query->where('gedcom_id', '=', $tree->id())
120 120
                     ->orWhereNull('gedcom_id');
121 121
             })
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Schema/Migration1.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,12 +22,12 @@
 block discarded – undo
22 22
 class Migration1 implements MigrationInterface
23 23
 {
24 24
     
25
-    /**
26
-     * {@inheritDoc}
27
-     * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
28
-     */
29
-    public function upgrade(): void
30
-    {
31
-        // These migrations have been merged into migration 2.
32
-    }
25
+	/**
26
+	 * {@inheritDoc}
27
+	 * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
28
+	 */
29
+	public function upgrade(): void
30
+	{
31
+		// These migrations have been merged into migration 2.
32
+	}
33 33
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Http/RequestHandlers/AncestorsListFamily.php 2 patches
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -35,73 +35,73 @@
 block discarded – undo
35 35
  */
36 36
 class AncestorsListFamily implements RequestHandlerInterface
37 37
 {
38
-    use ViewResponseTrait;
39
-
40
-    /**
41
-     * @var SosaModule $module
42
-     */
43
-    private $module;
44
-
45
-    /**
46
-     * @var SosaRecordsService $sosa_record_service
47
-     */
48
-    private $sosa_record_service;
49
-
50
-    /**
51
-     * Constructor for AncestorsListFamily Request Handler
52
-     *
53
-     * @param ModuleService $module_service
54
-     * @param SosaRecordsService $sosa_record_service
55
-     */
56
-    public function __construct(
57
-        ModuleService $module_service,
58
-        SosaRecordsService $sosa_record_service
59
-    ) {
60
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
61
-        $this->sosa_record_service = $sosa_record_service;
62
-    }
63
-
64
-    /**
65
-     * {@inheritDoc}
66
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
67
-     */
68
-    public function handle(ServerRequestInterface $request): ResponseInterface
69
-    {
70
-        $this->layout = 'layouts/ajax';
71
-
72
-        if ($this->module === null) {
73
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
74
-        }
75
-
76
-        $tree = $request->getAttribute('tree');
77
-        assert($tree instanceof Tree);
78
-
79
-        $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
80
-
81
-        $current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
82
-
83
-        if ($current_gen <= 0) {
84
-            return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY);
85
-        }
86
-
87
-        $list_families = $this->sosa_record_service->listAncestorFamiliesAtGeneration($tree, $user, $current_gen);
88
-        $nb_families_all = $list_families->count();
89
-
90
-        /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */
91
-        $list_families = $list_families->mapWithKeys(function (stdClass $value) use ($tree): ?array {
92
-                $fam = Registry::familyFactory()->make($value->f_id, $tree);
93
-                return ($fam !== null && $fam->canShow()) ? [(int) $value->majs_sosa => $fam] : null;
94
-        })->filter();
95
-
96
-        $nb_families_shown = $list_families->count();
97
-
98
-        return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [
99
-            'module_name'       =>  $this->module->name(),
100
-            'title'             =>  I18N::translate('Sosa Ancestors'),
101
-            'tree'              =>  $tree,
102
-            'list_families'     =>  $list_families,
103
-            'nb_families_all'   =>  $nb_families_all,
104
-            'nb_families_shown' =>  $nb_families_shown
105
-        ]);
106
-    }
38
+	use ViewResponseTrait;
39
+
40
+	/**
41
+	 * @var SosaModule $module
42
+	 */
43
+	private $module;
44
+
45
+	/**
46
+	 * @var SosaRecordsService $sosa_record_service
47
+	 */
48
+	private $sosa_record_service;
49
+
50
+	/**
51
+	 * Constructor for AncestorsListFamily Request Handler
52
+	 *
53
+	 * @param ModuleService $module_service
54
+	 * @param SosaRecordsService $sosa_record_service
55
+	 */
56
+	public function __construct(
57
+		ModuleService $module_service,
58
+		SosaRecordsService $sosa_record_service
59
+	) {
60
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
61
+		$this->sosa_record_service = $sosa_record_service;
62
+	}
63
+
64
+	/**
65
+	 * {@inheritDoc}
66
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
67
+	 */
68
+	public function handle(ServerRequestInterface $request): ResponseInterface
69
+	{
70
+		$this->layout = 'layouts/ajax';
71
+
72
+		if ($this->module === null) {
73
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
74
+		}
75
+
76
+		$tree = $request->getAttribute('tree');
77
+		assert($tree instanceof Tree);
78
+
79
+		$user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
80
+
81
+		$current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
82
+
83
+		if ($current_gen <= 0) {
84
+			return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY);
85
+		}
86
+
87
+		$list_families = $this->sosa_record_service->listAncestorFamiliesAtGeneration($tree, $user, $current_gen);
88
+		$nb_families_all = $list_families->count();
89
+
90
+		/** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */
91
+		$list_families = $list_families->mapWithKeys(function (stdClass $value) use ($tree): ?array {
92
+				$fam = Registry::familyFactory()->make($value->f_id, $tree);
93
+				return ($fam !== null && $fam->canShow()) ? [(int) $value->majs_sosa => $fam] : null;
94
+		})->filter();
95
+
96
+		$nb_families_shown = $list_families->count();
97
+
98
+		return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [
99
+			'module_name'       =>  $this->module->name(),
100
+			'title'             =>  I18N::translate('Sosa Ancestors'),
101
+			'tree'              =>  $tree,
102
+			'list_families'     =>  $list_families,
103
+			'nb_families_all'   =>  $nb_families_all,
104
+			'nb_families_shown' =>  $nb_families_shown
105
+		]);
106
+	}
107 107
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
         $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
80 80
 
81
-        $current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
81
+        $current_gen = (int)($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
82 82
 
83 83
         if ($current_gen <= 0) {
84 84
             return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY);
@@ -88,14 +88,14 @@  discard block
 block discarded – undo
88 88
         $nb_families_all = $list_families->count();
89 89
 
90 90
         /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */
91
-        $list_families = $list_families->mapWithKeys(function (stdClass $value) use ($tree): ?array {
91
+        $list_families = $list_families->mapWithKeys(function(stdClass $value) use ($tree): ?array {
92 92
                 $fam = Registry::familyFactory()->make($value->f_id, $tree);
93
-                return ($fam !== null && $fam->canShow()) ? [(int) $value->majs_sosa => $fam] : null;
93
+                return ($fam !== null && $fam->canShow()) ? [(int)$value->majs_sosa => $fam] : null;
94 94
         })->filter();
95 95
 
96 96
         $nb_families_shown = $list_families->count();
97 97
 
98
-        return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [
98
+        return $this->viewResponse($this->module->name().'::list-ancestors-fam-tab', [
99 99
             'module_name'       =>  $this->module->name(),
100 100
             'title'             =>  I18N::translate('Sosa Ancestors'),
101 101
             'tree'              =>  $tree,
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Http/RequestHandlers/MissingAncestorsList.php 2 patches
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -36,88 +36,88 @@
 block discarded – undo
36 36
  */
37 37
 class MissingAncestorsList implements RequestHandlerInterface
38 38
 {
39
-    use ViewResponseTrait;
40
-
41
-    /**
42
-     * @var SosaModule $module
43
-     */
44
-    private $module;
45
-
46
-    /**
47
-     * @var SosaRecordsService $sosa_record_service
48
-     */
49
-    private $sosa_record_service;
50
-
51
-    /**
52
-     * Constructor for MissingAncestorsList Request Handler
53
-     *
54
-     * @param ModuleService $module_service
55
-     * @param SosaRecordsService $sosa_record_service
56
-     */
57
-    public function __construct(
58
-        ModuleService $module_service,
59
-        SosaRecordsService $sosa_record_service
60
-    ) {
61
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
62
-        $this->sosa_record_service = $sosa_record_service;
63
-    }
64
-
65
-    /**
66
-     * {@inheritDoc}
67
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
68
-     */
69
-    public function handle(ServerRequestInterface $request): ResponseInterface
70
-    {
71
-        if ($this->module === null) {
72
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
73
-        }
74
-
75
-        $tree = $request->getAttribute('tree');
76
-        assert($tree instanceof Tree);
77
-
78
-        $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
79
-
80
-        /** @var SosaStatisticsService $sosa_stats_service */
81
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
82
-
83
-        $current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
84
-
85
-        $list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen);
86
-        $nb_missing_diff = $list_missing->sum(function (stdClass $value): int {
87
-            return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0);
88
-        });
89
-
90
-        $list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor {
91
-            $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
92
-            if ($indi !== null && $indi->canShowName()) {
93
-                return new MissingAncestor(
94
-                    $indi,
95
-                    (int) $value->majs_sosa,
96
-                    $value->majs_fat_id === null,
97
-                    $value->majs_mot_id === null
98
-                );
99
-            }
100
-            return null;
101
-        })->filter();
102
-
103
-        $nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int {
104
-            return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0);
105
-        });
106
-
107
-        return $this->viewResponse($this->module->name() . '::list-missing-page', [
108
-            'module_name'       =>  $this->module->name(),
109
-            'title'             =>  I18N::translate('Missing Ancestors'),
110
-            'tree'              =>  $tree,
111
-            'root_indi'         =>  $sosa_stats_service->rootIndividual(),
112
-            'max_gen'           =>  $sosa_stats_service->maxGeneration(),
113
-            'current_gen'       =>  $current_gen,
114
-            'list_missing'      =>  $list_missing,
115
-            'nb_missing_diff'   =>  $nb_missing_diff,
116
-            'nb_missing_shown'  =>  $nb_missing_shown,
117
-            'gen_completeness'  =>
118
-                $sosa_stats_service->totalAncestorsAtGeneration($current_gen) / pow(2, $current_gen - 1),
119
-            'gen_potential'     =>
120
-                $sosa_stats_service->totalAncestorsAtGeneration($current_gen - 1) / pow(2, $current_gen - 2)
121
-        ]);
122
-    }
39
+	use ViewResponseTrait;
40
+
41
+	/**
42
+	 * @var SosaModule $module
43
+	 */
44
+	private $module;
45
+
46
+	/**
47
+	 * @var SosaRecordsService $sosa_record_service
48
+	 */
49
+	private $sosa_record_service;
50
+
51
+	/**
52
+	 * Constructor for MissingAncestorsList Request Handler
53
+	 *
54
+	 * @param ModuleService $module_service
55
+	 * @param SosaRecordsService $sosa_record_service
56
+	 */
57
+	public function __construct(
58
+		ModuleService $module_service,
59
+		SosaRecordsService $sosa_record_service
60
+	) {
61
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
62
+		$this->sosa_record_service = $sosa_record_service;
63
+	}
64
+
65
+	/**
66
+	 * {@inheritDoc}
67
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
68
+	 */
69
+	public function handle(ServerRequestInterface $request): ResponseInterface
70
+	{
71
+		if ($this->module === null) {
72
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
73
+		}
74
+
75
+		$tree = $request->getAttribute('tree');
76
+		assert($tree instanceof Tree);
77
+
78
+		$user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
79
+
80
+		/** @var SosaStatisticsService $sosa_stats_service */
81
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
82
+
83
+		$current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
84
+
85
+		$list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen);
86
+		$nb_missing_diff = $list_missing->sum(function (stdClass $value): int {
87
+			return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0);
88
+		});
89
+
90
+		$list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor {
91
+			$indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
92
+			if ($indi !== null && $indi->canShowName()) {
93
+				return new MissingAncestor(
94
+					$indi,
95
+					(int) $value->majs_sosa,
96
+					$value->majs_fat_id === null,
97
+					$value->majs_mot_id === null
98
+				);
99
+			}
100
+			return null;
101
+		})->filter();
102
+
103
+		$nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int {
104
+			return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0);
105
+		});
106
+
107
+		return $this->viewResponse($this->module->name() . '::list-missing-page', [
108
+			'module_name'       =>  $this->module->name(),
109
+			'title'             =>  I18N::translate('Missing Ancestors'),
110
+			'tree'              =>  $tree,
111
+			'root_indi'         =>  $sosa_stats_service->rootIndividual(),
112
+			'max_gen'           =>  $sosa_stats_service->maxGeneration(),
113
+			'current_gen'       =>  $current_gen,
114
+			'list_missing'      =>  $list_missing,
115
+			'nb_missing_diff'   =>  $nb_missing_diff,
116
+			'nb_missing_shown'  =>  $nb_missing_shown,
117
+			'gen_completeness'  =>
118
+				$sosa_stats_service->totalAncestorsAtGeneration($current_gen) / pow(2, $current_gen - 1),
119
+			'gen_potential'     =>
120
+				$sosa_stats_service->totalAncestorsAtGeneration($current_gen - 1) / pow(2, $current_gen - 2)
121
+		]);
122
+	}
123 123
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -80,19 +80,19 @@  discard block
 block discarded – undo
80 80
         /** @var SosaStatisticsService $sosa_stats_service */
81 81
         $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
82 82
 
83
-        $current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
83
+        $current_gen = (int)($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
84 84
 
85 85
         $list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen);
86
-        $nb_missing_diff = $list_missing->sum(function (stdClass $value): int {
86
+        $nb_missing_diff = $list_missing->sum(function(stdClass $value): int {
87 87
             return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0);
88 88
         });
89 89
 
90
-        $list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor {
90
+        $list_missing = $list_missing->map(function(stdClass $value) use ($tree): ?MissingAncestor {
91 91
             $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
92 92
             if ($indi !== null && $indi->canShowName()) {
93 93
                 return new MissingAncestor(
94 94
                     $indi,
95
-                    (int) $value->majs_sosa,
95
+                    (int)$value->majs_sosa,
96 96
                     $value->majs_fat_id === null,
97 97
                     $value->majs_mot_id === null
98 98
                 );
@@ -100,11 +100,11 @@  discard block
 block discarded – undo
100 100
             return null;
101 101
         })->filter();
102 102
 
103
-        $nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int {
103
+        $nb_missing_shown = $list_missing->sum(function(MissingAncestor $value): int {
104 104
             return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0);
105 105
         });
106 106
 
107
-        return $this->viewResponse($this->module->name() . '::list-missing-page', [
107
+        return $this->viewResponse($this->module->name().'::list-missing-page', [
108 108
             'module_name'       =>  $this->module->name(),
109 109
             'title'             =>  I18N::translate('Missing Ancestors'),
110 110
             'tree'              =>  $tree,
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Http/RequestHandlers/AncestorsListIndividual.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -35,74 +35,74 @@
 block discarded – undo
35 35
  */
36 36
 class AncestorsListIndividual implements RequestHandlerInterface
37 37
 {
38
-    use ViewResponseTrait;
39
-
40
-    /**
41
-     * @var SosaModule $module
42
-     */
43
-    private $module;
44
-
45
-    /**
46
-     * @var SosaRecordsService $sosa_record_service
47
-     */
48
-    private $sosa_record_service;
49
-
50
-    /**
51
-     * Constructor for AncestorsListIndividual Request Handler
52
-     *
53
-     * @param ModuleService $module_service
54
-     * @param SosaRecordsService $sosa_record_service
55
-     */
56
-    public function __construct(
57
-        ModuleService $module_service,
58
-        SosaRecordsService $sosa_record_service
59
-    ) {
60
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
61
-        $this->sosa_record_service = $sosa_record_service;
62
-    }
63
-
64
-    /**
65
-     * {@inheritDoc}
66
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
67
-     */
68
-    public function handle(ServerRequestInterface $request): ResponseInterface
69
-    {
70
-        $this->layout = 'layouts/ajax';
71
-
72
-        if ($this->module === null) {
73
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
74
-        }
75
-
76
-        $tree = $request->getAttribute('tree');
77
-        assert($tree instanceof Tree);
78
-
79
-        $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
80
-
81
-        $current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
82
-
83
-        if ($current_gen <= 0) {
84
-            return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY);
85
-        }
86
-
87
-        $list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen);
88
-        $nb_ancestors_all = $list_ancestors->count();
89
-
90
-        /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */
91
-        $list_ancestors = $list_ancestors->mapWithKeys(function (stdClass $value) use ($tree): ?array {
92
-                $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
93
-                return ($indi !== null && $indi->canShowName()) ? [(int) $value->majs_sosa => $indi] : null;
94
-        })->filter();
95
-
96
-        $nb_ancestors_shown = $list_ancestors->count();
97
-
98
-        return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [
99
-            'module_name'       =>  $this->module->name(),
100
-            'title'             =>  I18N::translate('Sosa Ancestors'),
101
-            'tree'              =>  $tree,
102
-            'list_ancestors'    =>  $list_ancestors,
103
-            'nb_ancestors_all'  =>  $nb_ancestors_all,
104
-            'nb_ancestors_theor' =>  pow(2, $current_gen - 1),
105
-            'nb_ancestors_shown' =>  $nb_ancestors_shown
106
-        ]);
107
-    }
38
+	use ViewResponseTrait;
39
+
40
+	/**
41
+	 * @var SosaModule $module
42
+	 */
43
+	private $module;
44
+
45
+	/**
46
+	 * @var SosaRecordsService $sosa_record_service
47
+	 */
48
+	private $sosa_record_service;
49
+
50
+	/**
51
+	 * Constructor for AncestorsListIndividual Request Handler
52
+	 *
53
+	 * @param ModuleService $module_service
54
+	 * @param SosaRecordsService $sosa_record_service
55
+	 */
56
+	public function __construct(
57
+		ModuleService $module_service,
58
+		SosaRecordsService $sosa_record_service
59
+	) {
60
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
61
+		$this->sosa_record_service = $sosa_record_service;
62
+	}
63
+
64
+	/**
65
+	 * {@inheritDoc}
66
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
67
+	 */
68
+	public function handle(ServerRequestInterface $request): ResponseInterface
69
+	{
70
+		$this->layout = 'layouts/ajax';
71
+
72
+		if ($this->module === null) {
73
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
74
+		}
75
+
76
+		$tree = $request->getAttribute('tree');
77
+		assert($tree instanceof Tree);
78
+
79
+		$user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
80
+
81
+		$current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
82
+
83
+		if ($current_gen <= 0) {
84
+			return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY);
85
+		}
86
+
87
+		$list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen);
88
+		$nb_ancestors_all = $list_ancestors->count();
89
+
90
+		/** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */
91
+		$list_ancestors = $list_ancestors->mapWithKeys(function (stdClass $value) use ($tree): ?array {
92
+				$indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
93
+				return ($indi !== null && $indi->canShowName()) ? [(int) $value->majs_sosa => $indi] : null;
94
+		})->filter();
95
+
96
+		$nb_ancestors_shown = $list_ancestors->count();
97
+
98
+		return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [
99
+			'module_name'       =>  $this->module->name(),
100
+			'title'             =>  I18N::translate('Sosa Ancestors'),
101
+			'tree'              =>  $tree,
102
+			'list_ancestors'    =>  $list_ancestors,
103
+			'nb_ancestors_all'  =>  $nb_ancestors_all,
104
+			'nb_ancestors_theor' =>  pow(2, $current_gen - 1),
105
+			'nb_ancestors_shown' =>  $nb_ancestors_shown
106
+		]);
107
+	}
108 108
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
         $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser();
80 80
 
81
-        $current_gen = (int) ($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
81
+        $current_gen = (int)($request->getAttribute('gen') ?? $request->getQueryParams()['gen'] ?? 0);
82 82
 
83 83
         if ($current_gen <= 0) {
84 84
             return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY);
@@ -88,14 +88,14 @@  discard block
 block discarded – undo
88 88
         $nb_ancestors_all = $list_ancestors->count();
89 89
 
90 90
         /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */
91
-        $list_ancestors = $list_ancestors->mapWithKeys(function (stdClass $value) use ($tree): ?array {
91
+        $list_ancestors = $list_ancestors->mapWithKeys(function(stdClass $value) use ($tree): ?array {
92 92
                 $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
93
-                return ($indi !== null && $indi->canShowName()) ? [(int) $value->majs_sosa => $indi] : null;
93
+                return ($indi !== null && $indi->canShowName()) ? [(int)$value->majs_sosa => $indi] : null;
94 94
         })->filter();
95 95
 
96 96
         $nb_ancestors_shown = $list_ancestors->count();
97 97
 
98
-        return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [
98
+        return $this->viewResponse($this->module->name().'::list-ancestors-indi-tab', [
99 99
             'module_name'       =>  $this->module->name(),
100 100
             'title'             =>  I18N::translate('Sosa Ancestors'),
101 101
             'tree'              =>  $tree,
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Http/RequestHandlers/SosaComputeModal.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,40 +29,40 @@
 block discarded – undo
29 29
  */
30 30
 class SosaComputeModal implements RequestHandlerInterface
31 31
 {
32
-    /**
33
-     * @var SosaModule $module
34
-     */
35
-    private $module;
32
+	/**
33
+	 * @var SosaModule $module
34
+	 */
35
+	private $module;
36 36
 
37
-    /**
38
-     * Constructor for SosaComputeModal Request Handler
39
-     *
40
-     * @param ModuleService $module_service
41
-     */
42
-    public function __construct(ModuleService $module_service)
43
-    {
44
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
45
-    }
37
+	/**
38
+	 * Constructor for SosaComputeModal Request Handler
39
+	 *
40
+	 * @param ModuleService $module_service
41
+	 */
42
+	public function __construct(ModuleService $module_service)
43
+	{
44
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
45
+	}
46 46
 
47
-    /**
48
-     * {@inheritDoc}
49
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
50
-     */
51
-    public function handle(ServerRequestInterface $request): ResponseInterface
52
-    {
53
-        if ($this->module === null) {
54
-            return response(
55
-                I18N::translate('The attached module could not be found.'),
56
-                StatusCodeInterface::STATUS_NOT_FOUND
57
-            );
58
-        }
47
+	/**
48
+	 * {@inheritDoc}
49
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
50
+	 */
51
+	public function handle(ServerRequestInterface $request): ResponseInterface
52
+	{
53
+		if ($this->module === null) {
54
+			return response(
55
+				I18N::translate('The attached module could not be found.'),
56
+				StatusCodeInterface::STATUS_NOT_FOUND
57
+			);
58
+		}
59 59
 
60
-        $tree = $request->getAttribute('tree');
61
-        assert($tree instanceof Tree);
60
+		$tree = $request->getAttribute('tree');
61
+		assert($tree instanceof Tree);
62 62
 
63
-        return response(view($this->module->name() . '::modals/sosa-compute', [
64
-            'tree'          => $tree,
65
-            'xref'          =>  $request->getAttribute('xref')
66
-        ]));
67
-    }
63
+		return response(view($this->module->name() . '::modals/sosa-compute', [
64
+			'tree'          => $tree,
65
+			'xref'          =>  $request->getAttribute('xref')
66
+		]));
67
+	}
68 68
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@
 block discarded – undo
60 60
         $tree = $request->getAttribute('tree');
61 61
         assert($tree instanceof Tree);
62 62
 
63
-        return response(view($this->module->name() . '::modals/sosa-compute', [
63
+        return response(view($this->module->name().'::modals/sosa-compute', [
64 64
             'tree'          => $tree,
65 65
             'xref'          =>  $request->getAttribute('xref')
66 66
         ]));
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Http/RequestHandlers/SosaComputeAction.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -31,61 +31,61 @@
 block discarded – undo
31 31
  */
32 32
 class SosaComputeAction implements RequestHandlerInterface
33 33
 {
34
-    /**
35
-     * @var UserService $user_service
36
-     */
37
-    private $user_service;
34
+	/**
35
+	 * @var UserService $user_service
36
+	 */
37
+	private $user_service;
38 38
 
39
-    /**
40
-     * Constructor for SosaConfigAction Request Handler
41
-     *
42
-     * @param UserService $user_service
43
-     */
44
-    public function __construct(UserService $user_service)
45
-    {
46
-        $this->user_service = $user_service;
47
-    }
39
+	/**
40
+	 * Constructor for SosaConfigAction Request Handler
41
+	 *
42
+	 * @param UserService $user_service
43
+	 */
44
+	public function __construct(UserService $user_service)
45
+	{
46
+		$this->user_service = $user_service;
47
+	}
48 48
 
49
-    /**
50
-     * {@inheritDoc}
51
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
52
-     */
53
-    public function handle(ServerRequestInterface $request): ResponseInterface
54
-    {
55
-        $tree = $request->getAttribute('tree');
56
-        assert($tree instanceof Tree);
49
+	/**
50
+	 * {@inheritDoc}
51
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
52
+	 */
53
+	public function handle(ServerRequestInterface $request): ResponseInterface
54
+	{
55
+		$tree = $request->getAttribute('tree');
56
+		assert($tree instanceof Tree);
57 57
 
58
-        $params = $request->getParsedBody();
59
-        assert(is_array($params));
58
+		$params = $request->getParsedBody();
59
+		assert(is_array($params));
60 60
 
61
-        $user_id = (int) ($params['user_id'] ?? Auth::id() ?? 0);
62
-        $partial_from = $params['partial_from'] ?? null;
61
+		$user_id = (int) ($params['user_id'] ?? Auth::id() ?? 0);
62
+		$partial_from = $params['partial_from'] ?? null;
63 63
 
64
-        if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) {
65
-            $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id);
64
+		if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) {
65
+			$user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id);
66 66
 
67
-            /** @var SosaCalculatorService $sosa_calc_service */
68
-            $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]);
67
+			/** @var SosaCalculatorService $sosa_calc_service */
68
+			$sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]);
69 69
 
70
-            if (
71
-                $partial_from !== null &&
72
-                ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null
73
-            ) {
74
-                $res = $sosa_calc_service->computeFromIndividual($sosa_from);
75
-            } else {
76
-                $res = $sosa_calc_service->computeAll();
77
-            }
70
+			if (
71
+				$partial_from !== null &&
72
+				($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null
73
+			) {
74
+				$res = $sosa_calc_service->computeFromIndividual($sosa_from);
75
+			} else {
76
+				$res = $sosa_calc_service->computeAll();
77
+			}
78 78
 
79
-            return $res ?
80
-                response('', 200) :
81
-                response(
82
-                    I18N::translate('An error occurred while computing Sosa ancestors.'),
83
-                    StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR
84
-                );
85
-        }
86
-        return response(
87
-            I18N::translate('You do not have permission to modify the user.'),
88
-            StatusCodeInterface::STATUS_FORBIDDEN
89
-        );
90
-    }
79
+			return $res ?
80
+				response('', 200) :
81
+				response(
82
+					I18N::translate('An error occurred while computing Sosa ancestors.'),
83
+					StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR
84
+				);
85
+		}
86
+		return response(
87
+			I18N::translate('You do not have permission to modify the user.'),
88
+			StatusCodeInterface::STATUS_FORBIDDEN
89
+		);
90
+	}
91 91
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
         $params = $request->getParsedBody();
59 59
         assert(is_array($params));
60 60
 
61
-        $user_id = (int) ($params['user_id'] ?? Auth::id() ?? 0);
61
+        $user_id = (int)($params['user_id'] ?? Auth::id() ?? 0);
62 62
         $partial_from = $params['partial_from'] ?? null;
63 63
 
64 64
         if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) {
65 65
             $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id);
66 66
 
67 67
             /** @var SosaCalculatorService $sosa_calc_service */
68
-            $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]);
68
+            $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, ['tree' => $tree, 'user' => $user]);
69 69
 
70 70
             if (
71 71
                 $partial_from !== null &&
@@ -77,8 +77,7 @@  discard block
 block discarded – undo
77 77
             }
78 78
 
79 79
             return $res ?
80
-                response('', 200) :
81
-                response(
80
+                response('', 200) : response(
82 81
                     I18N::translate('An error occurred while computing Sosa ancestors.'),
83 82
                     StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR
84 83
                 );
Please login to merge, or discard this patch.