Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
cron_job_manage_pending_accounts.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/system/cron/cron_job/cron_job.inc';
19 require_once SQ_FUDGE_PATH.'/db_extras/db_extras.inc';
20 
33 {
34 
35 
42  function __construct($assetid=0)
43  {
44  parent::__construct($assetid);
45 
46  }//end constructor
47 
48 
60  function create(&$link)
61  {
62  require_once SQ_CORE_PACKAGE_PATH.'/system/system_asset_fns.inc';
63  if (!system_asset_fns_create_pre_check($this)) {
64  return FALSE;
65  }
66  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
67  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
68 
69  if ($linkid = parent::create($link)) {
70  if (!system_asset_fns_create_cleanup($this)) {
71  $linkid = FALSE;
72  }
73  }
74 
75  if ($linkid) {
76  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
77  } else {
78  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
79  }
80 
81  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
82  return $linkid;
83 
84  }//end create()
85 
86 
96  function _getName($short_name=FALSE)
97  {
98  return $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->type(), 'name');
99 
100  }//end _getName()
101 
102 
109  function canClone()
110  {
111  return FALSE;
112 
113  }//end canClone()
114 
115 
127  function morph($new_type_code)
128  {
129  trigger_localised_error('CRON0024', E_USER_WARNING, $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($this->type(), 'name'));
130  return FALSE;
131 
132  }//end morph()
133 
134 
143  function canDelete()
144  {
145  return FALSE;
146 
147  }//end canDelete()
148 
149 
163  function _exec(&$msg)
164  {
165  $assetids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('page_account_manager', FALSE);
166 
167  foreach($assetids as $assetid) {
168  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
169 
170  // Get the pending accounts group, if it exists
171  $pending_group_link = $GLOBALS['SQ_SYSTEM']->am->getLink($assetid, NULL, 'user_group', TRUE, 'pending_accounts');
172  if ($asset->attr('use_email_validation') && !empty($pending_group_link)) {
173  $pending_group = $GLOBALS['SQ_SYSTEM']->am->getAsset($pending_group_link['minorid']);
174 
175  // RESEND VALIDATION TIMEOUT //
176  $resend_period = $asset->attr('resend_validation_period');
177  if ($resend_period > 0) {
178  $date_sql = db_extras_todate(MatrixDAL::getDbType(), ':created', FALSE);
179 
180  $sql = 'SELECT
181  a.assetid, l.linkid
182  FROM sq_ast a
183  JOIN sq_ast_lnk l
184  ON a.assetid = l.minorid
185  WHERE
186  l.majorid = :majorid AND
187  l.link_type = :link_type AND
188  a.created < '.$date_sql;
189 
190  $query = MatrixDAL::preparePdoQuery($sql);
191  MatrixDAL::bindValueToPdo($query, 'majorid', $pending_group->id);
192  MatrixDAL::bindValueToPdo($query, 'link_type', SQ_LINK_TYPE_1);
193  MatrixDAL::bindValueToPdo($query, 'created', ts_iso8601(time() - $resend_period));
194  $user_assetids = MatrixDAL::executePdoAll($query);
195 
196  foreach($user_assetids as $user_row) {
197 
198  $user_assetid = $user_row['assetid'];
199 
200  $resent_link = $GLOBALS['SQ_SYSTEM']->am->getLinkByAsset($pending_group->id, $user_assetid, SQ_LINK_NOTICE, 'validation_email_resent');
201  if (!empty($resent_link)) continue;
202 
203  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($user_assetid);
204  if(empty($user)) {
205  trigger_error("User #".$user_assetid." doesn't exist", E_USER_WARNING);
206  continue;
207  }
208  // Resend the validation and create a notice link so email does not get resent in future cron runs.
209  if ($asset->resendValidation($user->attr('username'))) $GLOBALS['SQ_SYSTEM']->am->createAssetLink($pending_group, $user, SQ_LINK_NOTICE, 'validation_email_resent');
210 
211  unset($user);
212 
213  }
214  }
215 
216  // REMOVE ACCOUNT TIMEOUT //
217  $remove_period = $asset->attr('remove_account_period');
218  if ($remove_period > 0) {
219  $date_sql = db_extras_todate(MatrixDAL::getDbType(), ':created', FALSE);
220 
221  $sql = 'SELECT
222  a.assetid, l.linkid
223  FROM sq_ast a
224  JOIN sq_ast_lnk l
225  ON a.assetid = l.minorid
226  WHERE
227  l.majorid = :majorid AND
228  a.created < '.$date_sql.' AND
229  l.link_type < '.SQ_SC_LINK_SIGNIFICANT;
230 
231 
232  $query = MatrixDAL::preparePdoQuery($sql);
233  MatrixDAL::bindValueToPdo($query, 'majorid', $pending_group->id);
234  MatrixDAL::bindValueToPdo($query, 'created', ts_iso8601(time() - $remove_period));
235  $user_assetids = MatrixDAL::executePdoAll($query);
236 
237  foreach($user_assetids as $user_row) {
238  $user_assetid = $user_row['assetid'];
239  $user_linkid = $user_row['linkid'];
240 
241  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($user_assetid);
242  if(empty($user)) {
243  trigger_error("User #".$user_assetid." doesn't exist", E_USER_WARNING);
244  continue;
245  }
246  $GLOBALS['SQ_SYSTEM']->am->trashAsset($user_assetid);
247 
248  // trick the user asset into thinking we're purging the
249  // assets (which we are, just not from the trash), so it
250  // will release its hold on its inbox and workspace
251  $GLOBALS['SQ_PURGING_TRASH'] = TRUE;
252 
253  // Delete the inbox and remove its URLs
254  $inbox_link = $user->getInboxLink();
255  $inbox = $GLOBALS['SQ_SYSTEM']->am->getAsset($inbox_link['minorid']);
256  $GLOBALS['SQ_SYSTEM']->am->trashAsset($inbox->id);
257  $inbox->updateLookups();
258 
259  // Delete the workspace and remove its URLs
260  $workspace = $user->getWorkspace();
261  $GLOBALS['SQ_SYSTEM']->am->trashAsset($workspace->id);
262  $workspace->updateLookups();
263 
264  $inbox->delete(false);
265  $workspace->delete(false);
266  unset($GLOBALS['SQ_PURGING_TRASH']);
267 
268  // Delete the account
269  $user->delete(false);
270 
271  unset($user);
272  }
273  }
274 
275  unset($asset);
276 
277  }//end if
278  }//end foreach
279 
280  return SQ_CRON_JOB_COMPLETED;
281 
282  }//end _exec()
283 
284 
295  function run()
296  {
297  $res = parent::run();
298  if ($res & SQ_CRON_JOB_REMOVE) {
299  $res = $res - SQ_CRON_JOB_REMOVE;
300  }
301  return $res;
302 
303  }//end run()
304 
305 
306 }//end class
307 
308 ?>