17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
42 $this->uses_trans = FALSE;
43 parent::__construct($code_name);
44 $GLOBALS[
'SQ_SYSTEM']->lm->includePackageStrings(
'bulkmail');
60 return parent::getCodeName().
'-'.$this->_running_vars[
'file_info'][
'name'];
73 return translate(
'bm_hipo_name_delete_bmail_user');
89 'name' => translate(
'bm_hipo_deleting_bmail_users'),
90 'function_call' => Array(
91 'process_function' =>
'processDelete',
93 'running_mode' =>
'server',
98 'allow_cancel' => TRUE,
113 while (!empty($this->_running_vars[
'todo_asset_users'])) {
114 if (!$this->
processDelete($this->_steps[0], get_class($this))) {
132 if (!isset($this->_running_vars[
'email_list'])) {
134 require_once SQ_FUDGE_PATH.
'/csv/csv.inc';
135 $csv =
new CSV($this->_running_vars[
'file_info'][
'tmp_name']);
140 foreach ($csv->values as $line_value) {
141 $this->_running_vars[
'todo_asset_users'][$i][
'email'] = trim($line_value[0]);
145 $emails = $this->_running_vars[
'email_list'];
147 foreach ($emails as $email) {
148 $this->_running_vars[
'todo_asset_users'][$i][
'email'] = $email;
152 $this->_running_vars[
'done_asset_users'] = Array();
153 return parent::prepare();
169 if (!empty($this->_running_vars[
'todo_asset_users'])) {
172 $am = $GLOBALS[
'SQ_SYSTEM']->am;
173 $am->includeAsset(
'bulkmail_user');
174 $index = array_shift(array_keys($this->_running_vars[
'todo_asset_users']));
175 $email = $this->_running_vars[
'todo_asset_users'][$index][
'email'];
180 if (empty($this->_running_vars[
'root_nodes'])) {
182 $am->purgeAsset($user->id);
183 $step_data[
'message'] =
"Deleting Bulkmail User \"$user->name\" (#$user->id)";
186 $root_nodes = $this->_running_vars[
'root_nodes'];
187 for (reset($root_nodes); NULL !== ($k = key($root_nodes)); next($root_nodes)) {
190 $treeid_sql =
'SELECT rt.treeid AS treeid FROM sq_ast_lnk rl INNER JOIN sq_ast_lnk_tree rt ON rl.linkid=rt.linkid WHERE rl.minorid IN ('.implode(
',', $root_nodes).
')';
191 $treeid_result = NULL;
195 }
catch (Exception $e) {
196 throw new Exception($e->getMessage());
200 if (!empty($treeid_result)) {
202 $bind_vars = Array();
203 foreach ($treeid_result as $treeid_index => $each_treeid) {
204 if (!empty($each_treeid[
'treeid'])) {
205 $bind_vars[
'treeid_'.$treeid_index] = $each_treeid[
'treeid'].
'%';
206 if (!empty($treeid_index)) $under_tree .=
' OR ';
207 $under_tree .=
't.treeid LIKE :treeid_'.$treeid_index;
214 if (!empty($under_tree)) {
217 'select' =>
'SELECT l.linkid',
218 'from' =>
'FROM sq_ast_lnk l',
219 'join' =>
'INNER JOIN sq_ast_lnk_tree t ON l.linkid=t.linkid',
220 'where' =>
'WHERE l.minorid=:bulkmail_user_id',
223 'select' =>
'SELECT l.linkid',
224 'from' =>
'FROM sq_ast_lnk l',
225 'join' =>
'INNER JOIN sq_ast_lnk_tree t ON l.linkid=t.linkid',
226 'where' =>
'WHERE l.minorid=:bulkmail_user_id AND '.$under_tree,
228 $result_all_links = NULL;
229 $result_wanted_links = NULL;
235 foreach ($bind_vars as $bind_name => $bind_value) {
240 }
catch (Exception $e) {
241 throw new Exception($e->getMessage());
244 if (!empty($result_all_links) && !empty($result_wanted_links)) {
246 $all_links = Array();
247 foreach ($result_all_links as $link_info) {
248 if (!empty($link_info[
'linkid'])) {
249 $all_links[] = $link_info[
'linkid'];
252 $wanted_links = Array();
253 foreach ($result_wanted_links as $wanted_link_info) {
254 if (!empty($wanted_link_info[
'linkid'])) {
255 $wanted_links[] = $wanted_link_info[
'linkid'];
260 if (!empty($this->_running_vars[
'link_asset'][
'assetid'])) {
261 $to_parentid = $this->_running_vars[
'link_asset'][
'assetid'];
262 $link_type = $this->_running_vars[
'link_asset'][
'link_type'];
263 foreach ($wanted_links as $linkid) {
264 $am->moveLink($linkid, $to_parentid, $link_type, -1);
266 $step_data[
'message'] =
"Moving Bulkmail User \"$user->name\" (#$user->id)";
269 if ((count($all_links) == 1) || (count($wanted_links) == count($all_links))) {
271 $am->purgeAsset($user->id);
272 $step_data[
'message'] =
"Deleting Bulkmail User \"$user->name\" (#$user->id)";
275 foreach ($wanted_links as $linkid) {
276 $am->deleteAssetLink($linkid);
278 $step_data[
'message'] =
"Deleting Bulkmail User \"$user->name\" (#$user->id)";
286 $step_data[
'message'] = translate(
'bm_deleting_bmail_user', $email);
289 $this->_running_vars[
'done_asset_users'][] = $email;
292 unset($this->_running_vars[
'todo_asset_users'][$index]);
293 $am->forgetAsset($user);
298 if (empty($this->_running_vars[
'todo_asset_users'])) {
299 $step_data[
'percent_done'] = 100;
300 $step_data[
'complete'] = TRUE;
302 $total = count($this->_running_vars[
'todo_asset_users']) + count($this->_running_vars[
'done_asset_users']);
303 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_asset_users']) / $total) * 100;
304 $step_data[
'complete'] = FALSE;
325 $bind_vars[
'email'] = $email;
327 }
catch (Exception $e) {
328 throw new Exception(
"Unable to get existing bulkmail user due to database error: ".$e->getMessage());
332 if (!is_null($assetid) && !empty($assetid)) {
333 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);