public function run()
 {
     global $tree;
     include_once "Modules/Survey/classes/class.ilObjSurvey.php";
     $status = ilCronJobResult::STATUS_NO_ACTION;
     $message = array();
     $root = $tree->getNodeData(ROOT_FOLDER_ID);
     foreach ($tree->getSubTree($root, false, "svy") as $svy_ref_id) {
         $svy = new ilObjSurvey($svy_ref_id);
         if ($svy->checkReminder()) {
             $message[] = $svy_ref_id;
             $status = ilCronJobResult::STATUS_OK;
         }
     }
     $result = new ilCronJobResult();
     $result->setStatus($status);
     if (sizeof($message)) {
         $result->setMessage("Ref-Ids: " . implode(", ", $message));
         $result->setCode("#" . sizeof($message));
     }
     return $result;
 }
 public function run()
 {
     global $ilSetting;
     $status = ilCronJobResult::STATUS_NO_ACTION;
     $error_message = null;
     try {
         include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
         ilRpcClientFactory::factory('RPCIndexHandler')->index(CLIENT_ID . '_' . $ilSetting->get('inst_id', 0), true);
     } catch (XML_RPC2_FaultException $e) {
         $error_message = $e->getMessage();
     } catch (Exception $e) {
         $error_message = $e->getMessage();
     }
     $result = new ilCronJobResult();
     if ($error_message) {
         $result->setMessage($error_message);
         $status = ilCronJobResult::STATUS_CRASHED;
     } else {
         $status = ilCronJobResult::STATUS_OK;
     }
     $result->setStatus($status);
     return $result;
 }
 /**
  * Reset job
  * 
  * @param ilCronJob $a_job
  */
 public static function resetJob(ilCronJob $a_job)
 {
     global $ilDB;
     include_once "Services/Cron/classes/class.ilCronJobResult.php";
     $result = new ilCronJobResult();
     $result->setStatus(ilCronJobResult::STATUS_RESET);
     $result->setCode("job_manual_reset");
     $result->setMessage("Cron job re-activated by admin");
     self::updateJobResult($a_job, $result, true);
     $ilDB->manipulate("UPDATE cron_job" . " SET running_ts = " . $ilDB->quote(0, "integer") . " , alive_ts = " . $ilDB->quote(0, "integer") . " , job_result_ts = " . $ilDB->quote(0, "integer") . " WHERE job_id = " . $ilDB->quote($a_job->getId(), "text"));
     self::activateJob($a_job, true);
 }
 public function run()
 {
     global $ilLog;
     $status = ilCronJobResult::STATUS_NO_ACTION;
     $messages = array();
     foreach (ilLDAPServer::_getCronServerIds() as $server_id) {
         try {
             $this->current_server = new ilLDAPServer($server_id);
             $this->current_server->doConnectionCheck();
             $ilLog->write("LDAP: starting user synchronization for " . $this->current_server->getName());
             $this->ldap_query = new ilLDAPQuery($this->current_server);
             $this->ldap_query->bind(IL_LDAP_BIND_DEFAULT);
             if (is_array($users = $this->ldap_query->fetchUsers())) {
                 // Deactivate ldap users that are not in the list
                 $this->deactivateUsers($this->current_server, $users);
             }
             if (count($users)) {
                 $ilLog->write("LDAP: Starting update/creation of users ...");
                 $this->ldap_to_ilias = new ilLDAPAttributeToUser($this->current_server);
                 $this->ldap_to_ilias->setNewUserAuthMode($this->current_server->getAuthenticationMappingKey());
                 #$ilLog->write(print_r($users,true));
                 $this->ldap_to_ilias->setUserData($users);
                 $this->ldap_to_ilias->refresh();
                 $ilLog->write("LDAP: Finished update/creation");
                 $this->counter++;
             } else {
                 $ilLog->write("LDAP: No users for update/create. Aborting.");
             }
         } catch (ilLDAPQueryException $exc) {
             $mess = $exc->getMessage();
             $ilLog->write($mess);
             $messages[] = $mess;
         }
     }
     if ($this->counter) {
         $status = ilCronJobResult::STATUS_OK;
     }
     $result = new ilCronJobResult();
     if (sizeof($messages)) {
         $result->setMessage(implode("\n", $messages));
     }
     $result->setStatus($status);
     return $result;
 }
    public function run()
    {
        global $ilDB, $ilLog, $ilSetting, $lng;
        $status = ilCronJobResult::STATUS_NO_ACTION;
        $lng->loadLanguageModule('forum');
        if (!($last_run_datetime = $ilSetting->get('cron_forum_notification_last_date'))) {
            $last_run_datetime = null;
        }
        $numRows = 0;
        $types = array();
        $values = array();
        if ($last_run_datetime != null && checkDate(date('m', strtotime($last_run_datetime)), date('d', strtotime($last_run_datetime)), date('Y', strtotime($last_run_datetime)))) {
            $threshold = max(strtotime($last_run_datetime), strtotime('-' . (int) $this->settings->get('max_notification_age', 30) . ' days', time()));
        } else {
            $threshold = strtotime('-' . (int) $this->settings->get('max_notification_age', 30) . ' days', time());
        }
        $date_condition = ' frm_posts.pos_date >= %s AND ';
        $types[] = 'timestamp';
        $values[] = date('Y-m-d H:i:s', $threshold);
        $cj_start_date = date('Y-m-d H:i:s');
        /*** FORUMS ***/
        $res = $ilDB->queryf('
			SELECT 	frm_threads.thr_subject thr_subject, 
					frm_data.top_name top_name, 
					frm_data.top_frm_fk obj_id, 
					frm_notification.user_id user_id, 
					frm_posts.* 
			FROM 	frm_notification, frm_posts, frm_threads, frm_data 
			WHERE	' . $date_condition . ' frm_posts.pos_thr_fk = frm_threads.thr_pk
			AND 	frm_threads.thr_top_fk = frm_data.top_pk 
			AND 	frm_data.top_frm_fk = frm_notification.frm_id
			ORDER BY frm_posts.pos_date ASC', $types, $values);
        $numRows += $this->sendMails($res);
        /*** THREADS ***/
        $res = $ilDB->queryf('
			SELECT 	frm_threads.thr_subject thr_subject, 
					frm_data.top_name top_name, 
					frm_data.top_frm_fk obj_id, 
					frm_notification.user_id user_id, 
					frm_posts.* 
			FROM 	frm_notification, frm_posts, frm_threads, frm_data 
			WHERE 	' . $date_condition . ' frm_posts.pos_thr_fk = frm_threads.thr_pk
			AND		frm_threads.thr_pk = frm_notification.thread_id 
			AND 	frm_data.top_pk = frm_threads.thr_top_fk 
			ORDER BY frm_posts.pos_date ASC', $types, $values);
        $numRows += $this->sendMails($res);
        $ilSetting->set('cron_forum_notification_last_date', $cj_start_date);
        $mess = 'Send ' . $numRows . ' messages.';
        $ilLog->write(__METHOD__ . ': ' . $mess);
        $result = new ilCronJobResult();
        if ($numRows) {
            $status = ilCronJobResult::STATUS_OK;
            $result->setMessage($mess);
        }
        $result->setStatus($status);
        return $result;
    }
 public function run()
 {
     global $lng, $ilDB;
     $status = ilCronJobResult::STATUS_NO_ACTION;
     $status_details = null;
     $setting = new ilSetting("cron");
     $last_run = $setting->get(get_class($this));
     // #10284 - we already did send today, do nothing
     if ($last_run == date("Y-m-d")) {
         // #14005
         $status_details = "Did already run today.";
     } else {
         // gather objects and participants with notification setting
         $objects = array();
         $set = $ilDB->query("SELECT usr_id,keyword FROM usr_pref" . " WHERE " . $ilDB->like("keyword", "text", "grpcrs_ntf_%") . " AND value = " . $ilDB->quote("1", "text"));
         while ($row = $ilDB->fetchAssoc($set)) {
             $ref_id = substr($row["keyword"], 11);
             $type = ilObject::_lookupType($ref_id, true);
             if ($type) {
                 $objects[$type][$ref_id][] = $row["usr_id"];
             }
         }
         $counter = 0;
         if (sizeof($objects)) {
             $old_lng = $lng;
             include_once "Services/News/classes/class.ilNewsItem.php";
             foreach ($objects as $type => $ref_ids) {
                 // type is not needed for now
                 foreach ($ref_ids as $ref_id => $user_ids) {
                     // gather news per object
                     $news_item = new ilNewsItem();
                     if ($news_item->checkNewsExistsForGroupCourse($ref_id)) {
                         foreach ($user_ids as $user_id) {
                             // gather news for user
                             $user_news = $news_item->getNewsForRefId($ref_id, false, false, 1, false, false, false, false, $user_id);
                             if ($user_news) {
                                 $this->sendMail($user_id, $ref_id, $user_news);
                                 $counter++;
                             }
                         }
                     }
                 }
             }
             $lng = $old_lng;
         }
         // save last run
         $setting->set(get_class($this), date("Y-m-d"));
         if ($counter) {
             $status = ilCronJobResult::STATUS_OK;
         }
     }
     $result = new ilCronJobResult();
     $result->setStatus($status);
     if ($status_details) {
         $result->setMessage($status_details);
     }
     return $result;
 }