ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCertificateMigration.php
Go to the documentation of this file.
1<?php
2/*
3 +----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +----------------------------------------------------------------------------+
22*/
23
29{
31 protected $user_id;
32
35
37 protected $db;
38
44 public function __construct(int $user_id, \ilDBInterface $db = null)
45 {
46 global $DIC;
47
48 $this->user_id = $user_id;
49 if (null === $db) {
50 $db = $DIC->database();
51 }
52 $this->db = $db;
53 $this->information_object = new \ilCertificateMigrationInformationObject(
54 $this->getTaskInformations()
55 );
56 }
57
61 public function getTaskInformations() : array
62 {
63 $result = $this->db->queryF(
64 'SELECT * FROM il_cert_bgtask_migr WHERE usr_id = %s',
65 ['integer'],
66 [$this->user_id]
67 );
68 if ($result->numRows() == 1) {
69 $data = $this->db->fetchAssoc($result);
70 return $data;
71 }
72 return [];
73 }
74
79 {
81 }
82
86 public function getProgressedItemsAsPercent() : float
87 {
88 return (float) (100 / $this->information_object->getFoundItems() * $this->information_object->getProgressedItems());
89 }
90
94 public function isTaskStarted() : bool
95 {
96 return $this->information_object->getState() === \ilCertificateMigrationJobDefinitions::CERT_MIGRATION_STATE_INIT;
97 }
98
102 public function isTaskRunning() : bool
103 {
104 return (
105 $this->information_object->getLock() &&
106 $this->information_object->getState() === \ilCertificateMigrationJobDefinitions::CERT_MIGRATION_STATE_RUNNING
107 );
108 }
109
113 public function isTaskFailed() : bool
114 {
115 return (
116 $this->information_object->getState() === \ilCertificateMigrationJobDefinitions::CERT_MIGRATION_STATE_FAILED ||
117 $this->information_object->getState() === \ilCertificateMigrationJobDefinitions::CERT_MIGRATION_STATE_STOPPED ||
118 (
119 $this->information_object->getFinishedTime() === 0 &&
120 $this->information_object->getStartingTime() !== 0 &&
121 strtotime('-1 hours') > $this->information_object->getStartingTime()
122 )
123 );
124 }
125
129 public function isTaskFinished() : bool
130 {
131 return $this->information_object->getState() === \ilCertificateMigrationJobDefinitions::CERT_MIGRATION_STATE_FINISHED;
132 }
133}
$result
An exception for terminatinating execution or to throw for unit testing.
Class ilCertificateMigration.
__construct(int $user_id, \ilDBInterface $db=null)
ilCertificateMigration constructor.
Interface ilDBInterface.
global $DIC
Definition: saml.php:7
$data
Definition: bench.php:6