ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilUserCronCheckAccounts.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "Services/Cron/classes/class.ilCronJob.php";
5 
15 {
16  protected $counter = 0; // [int]
17 
18  public function getId()
19  {
20  return "user_check_accounts";
21  }
22 
23  public function getTitle()
24  {
25  global $lng;
26 
27  return $lng->txt("check_user_accounts");
28  }
29 
30  public function getDescription()
31  {
32  global $lng;
33 
34  return $lng->txt("check_user_accounts_desc");
35  }
36 
37  public function getDefaultScheduleType()
38  {
39  return self::SCHEDULE_TYPE_DAILY;
40  }
41 
42  public function getDefaultScheduleValue()
43  {
44  return;
45  }
46 
47  public function hasAutoActivation()
48  {
49  return false;
50  }
51 
52  public function hasFlexibleSchedule()
53  {
54  return false;
55  }
56 
57  public function run()
58  {
59  global $ilDB, $ilLog, $lng;
60 
62 
63  $now = time();
64  $two_weeks_in_seconds = $now + (60 * 60 * 24 * 14); // #14630
65 
66  // all users who are currently active and expire in the next 2 weeks
67  $query = "SELECT * FROM usr_data,usr_pref " .
68  "WHERE time_limit_message = '0' " .
69  "AND time_limit_unlimited = '0' " .
70  "AND time_limit_from < " . $ilDB->quote($now, "integer") . " " .
71  "AND time_limit_until > " . $ilDB->quote($now, "integer") . " " .
72  "AND time_limit_until < " . $ilDB->quote($two_weeks_in_seconds, "integer") . " " .
73  "AND usr_data.usr_id = usr_pref.usr_id " .
74  "AND keyword = " . $ilDB->quote("language", "text");
75 
76  $res = $ilDB->query($query);
77 
79  $senderFactory = $GLOBALS["DIC"]["mail.mime.sender.factory"];
80  $sender = $senderFactory->system();
81 
82  while ($row = $ilDB->fetchObject($res)) {
83  include_once 'Services/Mail/classes/class.ilMimeMail.php';
84 
85  $data['expires'] = $row->time_limit_until;
86  $data['email'] = $row->email;
87  $data['login'] = $row->login;
88  $data['usr_id'] = $row->usr_id;
89  $data['language'] = $row->value;
90  $data['owner'] = $row->time_limit_owner;
91 
92  // Send mail
93  $mail = new ilMimeMail();
94 
95  $mail->From($sender);
96  $mail->To($data['email']);
97  $mail->Subject($this->txt($data['language'], 'account_expires_subject'), true);
98  $mail->Body($this->txt($data['language'], 'account_expires_body') . " " . strftime('%Y-%m-%d %R', $data['expires']));
99  $mail->send();
100 
101  // set status 'mail sent'
102  $query = "UPDATE usr_data SET time_limit_message = '1' WHERE usr_id = '" . $data['usr_id'] . "'";
103  $ilDB->query($query);
104 
105  // Send log message
106  $ilLog->write('Cron: (checkUserAccounts()) sent message to ' . $data['login'] . '.');
107 
108  $this->counter++;
109  }
110 
112 
113  if ($this->counter) {
114  $status = ilCronJobResult::STATUS_OK;
115  }
116  $result = new ilCronJobResult();
117  $result->setStatus($status);
118  return $result;
119  }
120 
121  // #13288 / #12345
122  protected function txt($language, $key, $module = 'common')
123  {
124  include_once 'Services/Language/classes/class.ilLanguage.php';
125  return ilLanguage::_lookupEntry($language, $module, $key);
126  }
127 
128  protected function checkNotConfirmedUserAccounts()
129  {
130  global $ilDB, $ilLog;
131 
132  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
133  $oRegSettigs = new ilRegistrationSettings();
134 
135  $query = 'SELECT usr_id FROM usr_data '
136  . 'WHERE reg_hash IS NOT NULL '
137  . 'AND active = %s '
138  . 'AND create_date < %s';
139  $res = $ilDB->queryF(
140  $query,
141  array('integer', 'timestamp'),
142  array(0, date('Y-m-d H:i:s', time() - (int) $oRegSettigs->getRegistrationHashLifetime()))
143  );
144  while ($row = $ilDB->fetchAssoc($res)) {
145  $oUser = ilObjectFactory::getInstanceByObjId((int) $row['usr_id']);
146  $oUser->delete();
147  $ilLog->write('Cron: Deleted ' . $oUser->getLogin() . ' [' . $oUser->getId() . '] ' . __METHOD__);
148 
149  $this->counter++;
150  }
151  }
152 }
run()
Run job.
$result
txt($language, $key, $module='common')
Cron job application base class.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static _lookupEntry($a_lang_key, $a_mod, $a_id)
if($modEnd===false) $module
Definition: module.php:59
foreach($_POST as $key=> $value) $res
Class ilMimeMail.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$query
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
global $lng
Definition: privfeed.php:17
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
Cron job result data container.
$key
Definition: croninfo.php:18