public function run() { /** @var srCertificate $cert */ $certs = srCertificate::where(array('status' => srCertificate::STATUS_NEW))->get(); foreach ($certs as $cert) { // Force a reload of the members. If there are parallel cronjobs, only continue if status is still NEW $cert->read(); if ($cert->getStatus() != srCertificate::STATUS_NEW) { continue; } $cert->generate(); } // Also check for certificates with status DRAFT. They should be changed to NEW if the course is passed and the last access is more than xx minutes $certs = srCertificate::where(array('status' => srCertificate::STATUS_DRAFT))->get(); foreach ($certs as $cert) { $cert->read(); if ($cert->getStatus() != srCertificate::STATUS_DRAFT) { continue; } $max_diff_lp_seconds = $this->pl->config('max_diff_lp_seconds'); if ($max_diff_lp_seconds) { if ($last_access = $this->getLastLPStatus($cert)) { $diff = time() - $last_access; if ($diff > $max_diff_lp_seconds) { $cert->setStatus(srCertificate::STATUS_NEW); $cert->update(); } } } else { // If the setting max_diff_lp_seconds is "0", the NEW status is set anyway $cert->setStatus(srCertificate::STATUS_NEW); $cert->update(); } } }