disabled users cleanup

Author Message

Fabrice Girardot

Monday 03 March 2008 9:26:00 am

Hi,

I am looking for a script (or "something) to easily cleanup all disabled users. All suggestions are welcomed!

Thank you

Fabrice

--
Fabrice

Bruce Morrison

Monday 03 March 2008 3:27:52 pm

Hi Fabrice

Here you go:

<?php
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
include_once( 'kernel/classes/datatypes/ezuser/ezusersetting.php' );
include_once( 'kernel/classes/ezcontentobjecttreenodeoperations.php' );
include_once( 'lib/ezutils/classes/ezfunctionhandler.php' );


// Content Class ID of the user objects we want to purge
$userContentClassID = 44;

// Grab eZuser objects that are not activated
$users =& eZPersistentObject::fetchObjectList( eZUserSetting::definition(),
                                        null,
                                        array('is_enabled' => 0),true);
if($users)
{
  // build an array of user_ids
  $userIDs=array();
  foreach (array_keys($users) as $index)
  {
    $userSettings =& $users[$index];
    $userIDs[]=$userSettings->attribute('user_id');
  }
  // Get user content objects that were created more that a week ago
  $weekAgo = time()-3600*24*7;
  $cond = array('contentclass_id' => $userContentClassID,
                'id' => array($userIDs),
                'published' => array( '<', $weekAgo ) );

  $userObjects=eZPersistentObject::fetchObjectList( eZContentObject::definition(), null, $cond,true);
  if ($userObjects)
  {
    foreach (array_keys($userObjects) as $index)
    {
      $userObject =& $userObjects[$index];
      // Remove user
      $userObject->purge();
    }
  }
}
?>

This code removes users that are not active that have been created more than a week ago. Make sure you set the $userContentClassID value to the Content class Id of the user class you want to purge. I tend to create a specific "community" user class that is different to the user classes used for admin's & editors...just to be on the safe side. We don't want there removed!

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Fabrice Girardot

Monday 03 March 2008 11:56:29 pm

Thank you so much Bruce!

I am going to test that and try to run that as a cronjob.

--
Fabrice

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 21:07:11
Script start
Timing: Jan 18 2025 21:07:11
Module start 'layout'
Timing: Jan 18 2025 21:07:11
Module start 'content'
Timing: Jan 18 2025 21:07:12
Module end 'content'
Timing: Jan 18 2025 21:07:12
Script end

Main resources:

Total runtime0.8847 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 587.9063152.6250
Module start 'layout' 0.00560.0030 740.531339.4297
Module start 'content' 0.00860.8748 779.9609544.3203
Module end 'content' 0.88330.0013 1,324.281312.1875
Script end 0.8846  1,336.4688 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.4064160.0002
Check MTime0.00130.1508160.0001
Mysql Total
Database connection0.00090.101410.0009
Mysqli_queries0.833294.1856570.0146
Looping result0.00040.0472550.0000
Template Total0.855096.720.4275
Template load0.00230.259220.0011
Template processing0.852796.392020.4264
Template load and register function0.00010.014910.0001
states
state_id_array0.00070.081010.0007
state_identifier_array0.00070.083820.0004
Override
Cache load0.00190.2194200.0001
Sytem overhead
Fetch class attribute can translate value0.00060.067920.0003
Fetch class attribute name0.00150.168250.0003
XML
Image XML parsing0.00230.260420.0012
class_abstraction
Instantiating content class attribute0.00000.001660.0000
General
dbfile0.00210.2375220.0001
String conversion0.00000.001040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 15
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs