Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
bulkmail_post_office_management.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
18 
19 
33 {
34 
35 
40  function __construct(&$pm)
41  {
42  parent::__construct($pm);
43 
44  if (!strlen(SQ_CONF_DEFAULT_EMAIL)) {
45  trigger_localised_error('SYS0315', E_USER_WARNING);
46  }
47 
48  $this->vars = Array(
49  'name' => Array(
50  'added' => '0.1',
51  'type' => 'text',
52  'default' => '',
53  ),
54  'recipients' => Array(
55  'added' => '0.1',
56  'type' => 'serialise',
57  'default' => Array(),
58  'description' => 'The recipients to send this bulkmail to. All users/bulkmail_users in each group will become recipients',
59  ),
60  'content_id' => Array(
61  'added' => '0.1',
62  'type' => 'assetid',
63  'default' => '',
64  'description' => 'The asset we will be using as content in the email',
65  ),
66  'content_gen' => Array(
67  'added' => '0.1',
68  'type' => 'selection',
69  'default' => 'one_user',
70  'description' => 'The method of content generation',
71  'parameters' => Array(
72  'multiple' => FALSE,
73  'allow_empty' => FALSE,
74  'options' => Array(
75  'each_user' => 'Generate as recipient',
76  'one_user' => 'Generate as set user',
77  ),
78  ),
79  ),
80  'content_gen_as' => Array(
81  'added' => '0.1',
82  'type' => 'assetid',
83  'default' => '',
84  'description' => 'The user to generate the content with',
85  ),
86  'content_design' => Array(
87  'added' => '0.1',
88  'type' => 'assetid',
89  'default' => '',
90  'description' => 'The design to use for the content asset',
91  ),
92  'content_layout' => Array(
93  'added' => '0.1',
94  'type' => 'assetid',
95  'default' => '',
96  'description' => 'The layout to use for the content asset',
97  ),
98  'server_details' => Array(
99  'added' => '0.1',
100  'type' => 'serialise',
101  'default' => Array('driver' => 'sendmail'),
102  'description' => 'Details about which email server the bulkmails should be sent to',
103  ),
104  'from' => Array(
105  'added' => '0.1',
106  'type' => 'email',
107  'default' => SQ_CONF_DEFAULT_EMAIL,
108  'description' => 'Sending address as per RFC822',
109  ),
110  'subject' => Array(
111  'added' => '0.1',
112  'type' => 'text',
113  'default' => '',
114  'description' => 'Subject field of the email',
115  ),
116  'header_details' => Array(
117  'added' => '0.1',
118  'type' => 'serialise',
119  'default' => Array(),
120  'description' => 'Extra header detail fields',
121  ),
122  'threshold' => Array(
123  'added' => '0.1',
124  'type' => 'serialise',
125  'default' => Array(),
126  'description' => 'Threshold rules that will be enforced by the Bulk Mailer when it runs',
127  ),
128  'threshold_types' => Array(
129  'added' => '0.1',
130  'type' => 'serialise',
131  'default' => Array(
132  // bulkmail_threshold_rule_excluded_time
133  0 => Array(
134  'multiple' => TRUE,
135  'params' => Array(
136  'from' => 0,
137  'to' => 0,
138  'days' => Array(),
139  ),
140  ),
141  // bulkmail_threshold_rule_send_rate
142  1 => Array(
143  'multiple' => FALSE,
144  'params' => Array(
145  'value' => 60,
146  'unit' => 60,
147  ),
148  ),
149  ),
150  'description' => 'Threshold rule types and their default values',
151  ),
152  'bulkmail_mode' => Array(
153  'added' => '0.1',
154  'type' => 'selection',
155  'default' => 'live',
156  'parameters' => Array(
157  'multiple' => FALSE,
158  'allow_empty' => FALSE,
159  'options' => Array(
160  'live' => 'Live Mode',
161  'test' => 'Test Mode',
162  ),
163  ),
164  ),
165  );
166 
167  }//end constructor
168 
169 
170 
179  function _upgrade($current_version)
180  {
181  parent::_upgrade($current_version);
182 
183  if (version_compare($current_version, '0.2', '<')) {
184  echo('UPGRADING BULKMAIL POST OFFICE FROM '.$current_version."\n");
185  // Version 0.2 ownwards the sendmail path and arguments are retrieved from External tools config (tools.inc)
186  // rather than stored in attribute
187 
188  $count = 0;
189 
190  pre_echo('Updating Bulkmail Post Offices...');
191 
192  // Get all Search Page assets
193  $bulkmail_post_offices = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('bulkmail_post_office', FALSE, TRUE);
194 
195  $sendmail_path = '';
196  $sendmail_args = '';
197 
198  // Update assets
199  foreach ($bulkmail_post_offices as $id => $type) {
200  $post_office = $GLOBALS['SQ_SYSTEM']->am->getAsset($id);
201 
202  $server_details = $GLOBALS['SQ_SYSTEM']->am->getAttributeValuesByName('server_details', 'bulkmail_post_office', Array($post_office->id));
203  $server_details = unserialize($server_details[$post_office->id]);
204  if(isset($server_details['sendmail_path']) && !empty($server_details['sendmail_path']))
205  $sendmail_path = $server_details['sendmail_path'];
206  if(isset($server_details['sendmail_args']) && !empty($server_details['sendmail_args']))
207  $sendmail_args = $server_details['sendmail_args'];
208 
209  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($post_office, TRUE);
210  unset($post_office);
211 
212  $count++;
213  }//end foreach search pages
214 
215 
216  $vars['SQ_TOOL_SENDMAIL_PATH'] = $sendmail_path;
217  $vars['SQ_TOOL_SENDMAIL_ARGS'] = $sendmail_args;
218 
219  require_once SQ_INCLUDE_PATH.'/external_tools_config.inc';
220  $cfg = new External_Tools_Config();
221  if (!$cfg->save($vars, FALSE, TRUE)) {
222  echo "Sendmail path and arguments for bulkmail can not be saved\n";
223  return FALSE;
224  }
225 
226 
227  pre_echo('Updated - '.$count.' bulkmail post office(s)...');
228 
229  pre_echo('BULKMAIL POST OFFICE SUCCESSFULLY UPGRADED TO VERSION 0.2');
230  }//end if
231  return TRUE;
232 
233  }//end _upgrade()
234 
235 }//end class
236 ?>