ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
26 
27  $lng = $DIC['lng'];
28 
29  return $lng->txt("check_user_accounts");
30  }
31 
32  public function getDescription()
33  {
34  global $DIC;
35 
36  $lng = $DIC['lng'];
37 
38  return $lng->txt("check_user_accounts_desc");
39  }
40 
41  public function getDefaultScheduleType()
42  {
43  return self::SCHEDULE_TYPE_DAILY;
44  }
45 
46  public function getDefaultScheduleValue()
47  {
48  return;
49  }
50 
51  public function hasAutoActivation()
52  {
53  return false;
54  }
55 
56  public function hasFlexibleSchedule()
57  {
58  return false;
59  }
60 
61  public function run()
62  {
63  global $DIC;
64 
65  $ilDB = $DIC['ilDB'];
66  $ilLog = $DIC['ilLog'];
67  $lng = $DIC['lng'];
68 
70 
71  $now = time();
72  $two_weeks_in_seconds = $now + (60 * 60 * 24 * 14); // #14630
73 
74  // all users who are currently active and expire in the next 2 weeks
75  $query = "SELECT * FROM usr_data,usr_pref " .
76  "WHERE time_limit_message = '0' " .
77  "AND time_limit_unlimited = '0' " .
78  "AND time_limit_from < " . $ilDB->quote($now, "integer") . " " .
79  "AND time_limit_until > " . $ilDB->quote($now, "integer") . " " .
80  "AND time_limit_until < " . $ilDB->quote($two_weeks_in_seconds, "integer") . " " .
81  "AND usr_data.usr_id = usr_pref.usr_id " .
82  "AND keyword = " . $ilDB->quote("language", "text");
83 
84  $res = $ilDB->query($query);
85 
87  $senderFactory = $GLOBALS['DIC']["mail.mime.sender.factory"];
88  $sender = $senderFactory->system();
89 
90  while ($row = $ilDB->fetchObject($res)) {
91  include_once 'Services/Mail/classes/class.ilMimeMail.php';
92 
93  $data['expires'] = $row->time_limit_until;
94  $data['email'] = $row->email;
95  $data['login'] = $row->login;
96  $data['usr_id'] = $row->usr_id;
97  $data['language'] = $row->value;
98  $data['owner'] = $row->time_limit_owner;
99 
100  // Send mail
101  $mail = new ilMimeMail();
102 
103  $mail->From($sender);
104  $mail->To($data['email']);
105  $mail->Subject($this->txt($data['language'], 'account_expires_subject'), true);
106  $mail->Body($this->txt($data['language'], 'account_expires_body') . " " . strftime('%Y-%m-%d %R', $data['expires']));
107  $mail->send();
108 
109  // set status 'mail sent'
110  $query = "UPDATE usr_data SET time_limit_message = '1' WHERE usr_id = '" . $data['usr_id'] . "'";
111  $ilDB->query($query);
112 
113  // Send log message
114  $ilLog->write('Cron: (checkUserAccounts()) sent message to ' . $data['login'] . '.');
115 
116  $this->counter++;
117  }
118 
120 
121  if ($this->counter) {
122  $status = ilCronJobResult::STATUS_OK;
123  }
124  $result = new ilCronJobResult();
125  $result->setStatus($status);
126  return $result;
127  }
128 
129  // #13288 / #12345
130  protected function txt($language, $key, $module = 'common')
131  {
132  include_once 'Services/Language/classes/class.ilLanguage.php';
134  }
135 
136  protected function checkNotConfirmedUserAccounts()
137  {
138  global $DIC;
139 
140  $ilDB = $DIC['ilDB'];
141  $ilLog = $DIC['ilLog'];
142 
143  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
144  $oRegSettigs = new ilRegistrationSettings();
145 
146  $query = 'SELECT usr_id FROM usr_data '
147  . 'WHERE (reg_hash IS NOT NULL AND reg_hash != %s)'
148  . 'AND active = %s '
149  . 'AND create_date < %s';
150  $res = $ilDB->queryF(
151  $query,
152  array('text', 'integer', 'timestamp'),
153  array('', 0, date('Y-m-d H:i:s', time() - (int) $oRegSettigs->getRegistrationHashLifetime()))
154  );
155  while ($row = $ilDB->fetchAssoc($res)) {
156  $oUser = ilObjectFactory::getInstanceByObjId((int) $row['usr_id']);
157  $oUser->delete();
158  $ilLog->write('Cron: Deleted ' . $oUser->getLogin() . ' [' . $oUser->getId() . '] ' . __METHOD__);
159 
160  $this->counter++;
161  }
162  }
163 }
run()
Run job.
$result
txt($language, $key, $module='common')
global $DIC
Definition: saml.php:7
Cron job application base class.
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.
$lng
$query
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
$row
global $ilDB
Cron job result data container.
$key
Definition: croninfo.php:18
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
$data
Definition: bench.php:6