17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
44 $this->uses_trans = FALSE;
45 parent::__construct($code_name);
46 $GLOBALS[
'SQ_SYSTEM']->lm->includePackageStrings(
'bulkmail');
60 public static function paintConfig(&$o, $class, $write_access)
62 $o->openField(translate(
'bm_tool_import_bmail_user_hipo_job_import_threshold'));
65 text_box($class.
'[SQ_HIPO_BULKMAIL_USER_IMPORT_THRESHOLD]', SQ_HIPO_BULKMAIL_USER_IMPORT_THRESHOLD, 5);
67 echo SQ_HIPO_BULKMAIL_USER_IMPORT_THRESHOLD;
69 echo
' '.translate(
'assets');
85 'SQ_HIPO_BULKMAIL_USER_IMPORT_THRESHOLD' => Array(
'editable' => 1,
'default' => 5),
102 if (SQ_HIPO_BULKMAIL_USER_IMPORT_THRESHOLD == 0)
return 0;
103 if (!isset($this->_running_vars[
'todo_asset_users'])) {
106 $user_count = count($this->_running_vars[
'todo_asset_users']);
108 return (($user_count / SQ_HIPO_BULKMAIL_USER_IMPORT_THRESHOLD) * 100);
124 return parent::getCodeName().
'-'.$this->_running_vars[
'file_info'][
'name'];
137 return translate(
'bm_hipo_name_import_bmail_user');
153 'name' => translate(
'bm_hipo_importing_bmail_users'),
154 'function_call' => Array(
155 'process_function' =>
'processImport',
157 'running_mode' =>
'server',
162 'allow_cancel' => TRUE,
177 while (!empty($this->_running_vars[
'todo_asset_users'])) {
178 if (!$this->
processImport($this->_steps[0], get_class($this))) {
196 require_once SQ_FUDGE_PATH.
'/csv/csv.inc';
197 $csv =
new CSV($this->_running_vars[
'file_info'][
'tmp_name']);
200 if (isset($this->_running_vars[
'csv_header']) && $this->_running_vars[
'csv_header'] == TRUE) {
203 $csv->import($csv_start);
207 foreach ($csv->values as $line_value) {
208 $this->_running_vars[
'todo_asset_users'][$i][
'name'] = trim($line_value[0]);
209 $this->_running_vars[
'todo_asset_users'][$i][
'email'] = trim($line_value[1]);
212 $this->_running_vars[
'done_asset_users'] = Array();
213 return parent::prepare();
229 if (!empty($this->_running_vars[
'todo_asset_users'])) {
232 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bulkmail_user');
233 $array_keys = array_keys($this->_running_vars[
'todo_asset_users']);
234 $index = array_shift($array_keys);
235 $create_in = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->_running_vars[
'create_in_assetid']);
236 $name = $this->_running_vars[
'todo_asset_users'][$index][
'name'];
237 $email = $this->_running_vars[
'todo_asset_users'][$index][
'email'];
240 $user->setAttrValue(
'name', $name);
243 if ($this->_running_vars[
'new_link']) {
244 $old_reporting = error_reporting(0);
246 $status = $user->setAttrValue(
'email', $email);
247 if ($this->_running_vars[
'new_link']) {
248 error_reporting($old_reporting);
252 if ($name != $user->name) {
253 trigger_error(
"(Bulkmail User #$user->id) \"$name\" does not match existing name \"$user->name\"");
254 $step_data[
'message'] =
"Skipping \"$user->name\" (#$user->id)";
256 $create_in->createLink($user, SQ_LINK_TYPE_1);
257 $step_data[
'message'] =
"Linking \"$user->name\" (#$user->id)";
265 'asset' => $create_in,
266 'link_type' => SQ_LINK_TYPE_1,
268 $status = $user->create($link);
270 $step_data[
'message'] = translate(
'bm_importing_bmail_user', $email);
273 $this->_running_vars[
'done_asset_users'][] = $email;
276 unset($this->_running_vars[
'todo_asset_users'][$index]);
277 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($user);
278 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($create_in);
283 if (empty($this->_running_vars[
'todo_asset_users'])) {
284 $step_data[
'percent_done'] = 100;
285 $step_data[
'complete'] = TRUE;
287 $total = count($this->_running_vars[
'todo_asset_users']) + count($this->_running_vars[
'done_asset_users']);
288 $step_data[
'percent_done'] =(count($this->_running_vars[
'done_asset_users']) / $total) * 100;
289 $step_data[
'complete'] = FALSE;
310 $bind_vars[
'email'] = $email;
312 }
catch (Exception $e) {
313 throw new Exception(
'Unable to get existing bulkmail user due to database error: '.$e->getMessage());
317 if (!is_null($assetid)) {
318 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);