ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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(
107  $this->txt($data['language'], 'account_expires_body') . " " . strftime('%Y-%m-%d %R', $data['expires']) . "\n"
108  . "{$this->txt($data['language'], 'login')}: {$data['login']}"
109  );
110  $mail->send();
111 
112  // set status 'mail sent'
113  $query = "UPDATE usr_data SET time_limit_message = '1' WHERE usr_id = '" . $data['usr_id'] . "'";
114  $ilDB->query($query);
115 
116  // Send log message
117  $ilLog->write('Cron: (checkUserAccounts()) sent message to ' . $data['login'] . '.');
118 
119  $this->counter++;
120  }
121 
123 
124  if ($this->counter) {
125  $status = ilCronJobResult::STATUS_OK;
126  }
127  $result = new ilCronJobResult();
128  $result->setStatus($status);
129  return $result;
130  }
131 
132  // #13288 / #12345
133  protected function txt($language, $key, $module = 'common')
134  {
135  include_once 'Services/Language/classes/class.ilLanguage.php';
136  return ilLanguage::_lookupEntry($language, $module, $key);
137  }
138 
139  protected function checkNotConfirmedUserAccounts()
140  {
141  global $DIC;
142 
143  $ilDB = $DIC['ilDB'];
144  $ilLog = $DIC['ilLog'];
145 
146  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
147  $oRegSettigs = new ilRegistrationSettings();
148 
149  $query = 'SELECT usr_id FROM usr_data '
150  . 'WHERE (reg_hash IS NOT NULL AND reg_hash != %s)'
151  . 'AND active = %s '
152  . 'AND create_date < %s';
153  $res = $ilDB->queryF(
154  $query,
155  array('text', 'integer', 'timestamp'),
156  array('', 0, date('Y-m-d H:i:s', time() - (int) $oRegSettigs->getRegistrationHashLifetime()))
157  );
158  while ($row = $ilDB->fetchAssoc($res)) {
159  $oUser = ilObjectFactory::getInstanceByObjId((int) $row['usr_id']);
160  $oUser->delete();
161  $ilLog->write('Cron: Deleted ' . $oUser->getLogin() . ' [' . $oUser->getId() . '] ' . __METHOD__);
162 
163  $this->counter++;
164  }
165  }
166 }
run()
Run job.
$data
Definition: storeScorm.php:23
$result
txt($language, $key, $module='common')
Cron job application base class.
static _lookupEntry($a_lang_key, $a_mod, $a_id)
foreach($_POST as $key=> $value) $res
Class ilMimeMail.
$lng
global $DIC
Definition: goto.php:24
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$query
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObjAuthSettingsGUI.
global $ilDB
Cron job result data container.