/**
  * Clean up system by object ID-s
  * 
  * This function cleans up project objects recursively. It is also infinite 
  * loop safe because it will filter out ID-s that are already removed
  *
  * @param array $ids
  * @return null
  */
 function cleanUpByIds($ids)
 {
     static $cleaned_ids = array();
     // Remove objects that are already cleaned
     if (is_foreachable($ids)) {
         foreach ($ids as $k => $id) {
             if (isset($cleaned_ids[$id]) && $cleaned_ids[$id]) {
                 unset($ids[$k]);
             } else {
                 $cleaned_ids[$id] = false;
             }
             // if
         }
         // foreach
     }
     // if
     if (is_foreachable($ids)) {
         db_begin_work();
         Attachments::deleteByProjectObjectIds($ids);
         Subscriptions::deleteByObjectIds($ids);
         Assignments::deleteByObjectIds($ids);
         ActivityLogs::deleteByObjectIds($ids);
         StarredObjects::deleteByObjectIds($ids);
         Reminders::deleteByObjectIds($ids);
         search_index_remove($ids, 'ProjectObject');
         $rows = db_execute_all('SELECT DISTINCT id FROM ' . TABLE_PREFIX . 'project_objects WHERE parent_id IN (?)', $ids);
         if (is_foreachable($rows)) {
             $subobject_ids = array();
             foreach ($rows as $row) {
                 $subobject_ids[] = (int) $row['id'];
             }
             // foreach
             ProjectObjects::cleanUpByIds($subobject_ids);
         }
         // if
         ProjectObjects::delete(array('id IN (?)', $ids));
         foreach ($ids as $id) {
             $cleaned_ids[$id] = true;
         }
         // if
         db_commit();
     }
     // if
     return true;
 }