75        $this->user_id = 
$input[0]->getValue();
 
   78        $this->tree = 
$DIC->repositoryTree();
 
   79        $this->db = 
$DIC->database();
 
   81        $this->event_handler = 
$DIC[
'ilAppEventHandler'];
 
   82        $this->task_factory = 
$DIC->backgroundTasks()->taskFactory();
 
   83        $this->logger = 
$DIC->logger()->cert();
 
   88        $this->logger->debug(
'Started at ' . ($st_time = date(
'd.m.Y H:i:s')) . 
' for user with id: ' . $this->user_id);
 
   91        if (empty($task_informations)) {
 
   95            $this->logger->info(
'Parallel execution protection. Stopped task for user ' . $this->user_id . 
', because it is already running.');
 
   99        if ($task_informations[
'lock'] == 
true) {
 
  101            $this->logger->info(
'Parallel execution protection. Stopped task for user ' . $this->user_id . 
', because it is locked.');
 
  115            $this->logger->info(
'Start collection certificate data for user: ' . $this->user_id);
 
  117            foreach ($this->types as 
$type) {
 
  118                if (
$type === 
'scorm') {
 
  120                } elseif (
$type === 
'test') {
 
  122                } elseif (
$type === 
'exercise') {
 
  124                } elseif (
$type === 
'course') {
 
  132            $this->
updateTask([
'found_items' => $found_items]);
 
  133            $this->logger->debug(
'Found overall ' . $found_items . 
' items for user with id: ' . $this->user_id);
 
  134            $this->logger->info(
'Finished collecting certificate data for user: ' . $this->user_id);
 
  136            $processed_items = 0;
 
  142            $this->logger->info(
'Start migrating certificates for user: ' . 
$user->getId());
 
  144            foreach ($this->types as 
$type) {
 
  145                $this->logger->info(sprintf(
'Start preparing "%s" certificates', 
$type));
 
  149                        $class = ilTestPlaceholderValues::class;
 
  153                        $class = ilScormPlaceholderValues::class;
 
  157                        $class = ilExercisePlaceholderValues::class;
 
  161                        $class = ilCoursePlaceholderValues::class;
 
  164                $placeholder_values = 
new $class();
 
  170                                case $type == 
'course':
 
  175                                    $acquireTimestamp = $acquireDate->get(
IL_CAL_UNIX);
 
  179                                    $acquireTimestamp = 
$test 
  180                                        ->getTestResult(
$test->getActiveIdOfUser(
$user->getId()))[
'test'][
'result_tstamp'];
 
  187                                    $acquireTimestamp = $acquireDate->get(
IL_CAL_UNIX);
 
  189                        } 
catch (Exception $exception) {
 
  190                            $this->logger->warning(sprintf(
'Unable to gather aquired timestamp for certificate %s', $certificate_id));
 
  191                            $acquireTimestamp = 
null;
 
  193                        if ($acquireTimestamp === 
null || 0 === (
int) $acquireTimestamp) {
 
  194                            $acquireTimestamp = time();
 
  198                            $template = $template_repository->fetchFirstCreatedTemplate($certificate_id);
 
  199                        } 
catch (Exception $exception) {
 
  200                            $this->logger->warning(sprintf(
'Unable to gather template for certificate %s. Skipped.', $certificate_id));
 
  208                                $user->getFullname(),
 
  210                                $value_replacement->replace(
 
  211                                    $placeholder_values->getPlaceholderValues(
$user->getId(), $certificate_id),
 
  214                                json_encode($placeholder_values->getPlaceholderValues(
$user->getId(), $certificate_id)) ?? 
'',
 
  219                                $template->getBackgroundImagePath() ?? 
'',
 
  227                        'processed_items' => $processed_items,
 
  228                        'progress' => ($processed_items / $found_items) * 100
 
  233                $this->logger->info(sprintf(
'Finished preparing "%s" certificates', 
$type));
 
  236            $this->logger->info(
'Finished migrating certificates for user: ' . 
$user->getId());
 
  237        } 
catch (\Exception $e) {
 
  238            $this->logger->error($e->getMessage(), 
'error');
 
  241                'processed_items' => $processed_items,
 
  244            $output->setValue((
int) $e->getCode());
 
  250        $this->logger->debug(
'Finished at ' . (
$f_time = date(
'd.m.Y H:i:s')) . 
' after ' . (strtotime(
$f_time) - strtotime($st_time)) . 
' seconds');
 
  254            'processed_items' => $processed_items,
 
  258        $user->writePref(
'cert_migr_finished', 1);
 
  311            'SELECT * FROM ' . $this->db_table . 
' WHERE usr_id = %s',
 
  327        $this->logger->debug(
'Insert new entry for user with id: ' . $this->user_id);
 
  328        $this->db->insert($this->db_table, [
 
  329            'id' => [
'integer', $this->db->nextId($this->db_table)],
 
  330            'usr_id' => [
'integer', $this->user_id],
 
  331            'lock' => [
'integer', 
false],
 
  332            'found_items' => [
'integer', 0],
 
  333            'processed_items' => [
'integer', 0],
 
  334            'migrated_items' => [
'integer', 0],
 
  335            'progress' => [
'integer', 0],
 
  337            'started_ts' => [
'integer', strtotime(
'now')],
 
  338            'finished_ts' => 
null,
 
  349        if (array_key_exists(
'lock', 
$data)) {
 
  350            $updata[
'lock'] = [
'integer', 
$data[
'lock']];
 
  352        if (array_key_exists(
'found_items', 
$data)) {
 
  353            $updata[
'found_items'] = [
'integer', 
$data[
'found_items']];
 
  355        if (array_key_exists(
'processed_items', 
$data)) {
 
  356            $updata[
'processed_items'] = [
'integer', 
$data[
'processed_items']];
 
  358        if (array_key_exists(
'migrated_items', 
$data)) {
 
  359            $updata[
'migrated_items'] = [
'integer', 
$data[
'migrated_items']];
 
  361        if (array_key_exists(
'progress', 
$data)) {
 
  362            $updata[
'progress'] = [
'integer', 
$data[
'progress']];
 
  364        if (array_key_exists(
'state', 
$data)) {
 
  365            $updata[
'state'] = [
'text', 
$data[
'state']];
 
  367        if (array_key_exists(
'finished_ts', 
$data)) {
 
  368            if (is_string(
$data[
'finished_ts'])) {
 
  369                $data[
'finished_ts'] = strtotime(
$data[
'finished_ts']);
 
  371            $updata[
'finished_ts'] = [
'integer', 
$data[
'finished_ts']];
 
  373        $this->logger->debug(
'Update data: ' . json_encode($updata));
 
  374        if (!empty($updata)) {
 
  375            $this->logger->debug(
'Update entry for user with id: ' . $this->user_id);
 
  376            $this->db->update($this->db_table, $updata, [
'usr_id' => [
'integer', $this->user_id] ]);
 
  386        $this->logger->info(
'Trying to get scorm certificates for user: ' . $this->user_id);
 
  393            $root = $this->tree->getNodeData($this->tree->getRootId());
 
  394            foreach ($this->tree->getSubTree(
$root, 
true, 
"sahs") as $node) {
 
  395                $obj_ids[] = $node[
"obj_id"];
 
  398                foreach (\ilCertificate::areObjectsActive($obj_ids) as $objectId => $active) {
 
  404                            $this->logger->debug(
'Found inconsistent object, skipped migration: ' . $objectId);
 
  407                        $object->setSubType(
$type);
 
  409                        $lpdata = $completed = 
false;
 
  434                            $this->logger->info(sprintf(
 
  435                                'User did not complete SCORM object with obj_id %s, ignoring object for migration ...',
 
  441                        $this->logger->info(sprintf(
 
  442                            'User completed SCORM object with obj_id %s, considering object for migration ...',
 
  452        $this->logger->info(
'Got ' . count(
$data) . 
' scorm certificates for user: ' . $this->user_id);
 
  462        $this->logger->info(
'Trying to get test certificates for user: ' . $this->user_id);
 
  468            if (!$object || !($object instanceof \
ilObjTest)) {
 
  469                $this->logger->debug(
'Found inconsistent object, skipped migration: ' . $objectId);
 
  473            $session = new \ilTestSessionFactory($object);
 
  480        $this->logger->info(
'Got ' . count(
$data) . 
' test certificates for user: ' . $this->user_id);
 
  490        $this->logger->info(
'Trying to get exercise certificates for user: ' . $this->user_id);
 
  497                $this->logger->debug(
'Found inconsistent object, skipped migration: ' . $objectId);
 
  501            $adapter = new \ilExerciseCertificateAdapter($object);
 
  502            if ($adapter->hasUserCertificate($this->user_id)) {
 
  507        $this->logger->info(
'Got ' . count(
$data) . 
' exercise certificates for user: ' . $this->user_id);
 
  517        $this->logger->info(
'Trying to get course certificates for user: ' . $this->user_id);
 
  525            foreach ($obj_ids as $objectId) {
 
  528                    if (!$object || !($object instanceof \
ilObjCourse)) {
 
  529                        $this->logger->debug(
'Found inconsistent object, skipped migration: ' . $objectId);
 
  538        $this->logger->info(
'Got ' . count(
$data) . 
' course certificates for user: ' . $this->user_id);
 
An exception for terminatinating execution or to throw for unit testing.
const CERT_MIGRATION_STATE_INIT
const CERT_MIGRATION_RETURN_SUCCESS
const CERT_MIGRATION_STATE_FAILED
const CERT_MIGRATION_STATE_RUNNING
const CERT_MIGRATION_STATE_FINISHED
const CERT_MIGRATION_JOB_TABLE
const CERT_MIGRATION_RETURN_LOCKED
const CERT_MIGRATION_RETURN_ALREADY_RUNNING
Class ilCertificateMigrationJob.
getExpectedTimeOfTaskInSeconds()
getScormCertificates()
Get certificates for scorm objects.
getTestCertificates()
Get certificates for test objects.
getExerciseCertificates()
Get certificates for exercise objects.
run(array $input, Observer $observer)
getCourseCertificates()
Get certificates for course objects.
static isObjectActive($a_obj_id)
static _preloadListData($a_usr_ids, $a_obj_ids)
Get certificate/passed status for all given objects and users.
static _hasUserCertificate($a_usr_id, $a_obj_id)
Check if user has certificate for course.
static getDateTimeOfPassed($a_obj_id, $a_usr_id)
@classDescription Date and time handling
static _hasUserCompleted($a_obj_id, $a_user_id)
Lookup user object completion.
static _lookupStatusChanged($a_obj_id, $a_user_id)
Lookup status changed.
static _lookupFinishedUserExercises($a_user_id)
Get all exercises for user.
Class ilObjSCORMLearningModule.
static _lookupSubType($a_obj_id)
lookup subtype id (scorm, )
static _getCourseCompletionForUser($a_id, $a_user)
Get the completion of a SCORM module for a given user.
static _getCourseCompletionForUser($a_id, $a_user)
Get the completion of a SCORM module for a given user.
static getTestObjIdsWithActiveForUserId($userId)
static _enabledLearningProgress()
check wether learing progress is enabled or not
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
if(@file_exists(dirname(__FILE__).'/lang/eng.php')) $certificate
const ILIAS_VERSION_NUMERIC
heartbeat()
I'm still alive! If your calculation takes a really long time don't forget to use the heartbeat.