Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
hipo_config.inc
1 <?php
18 require_once SQ_LIB_PATH.'/config/config.inc';
19 
31 class HIPO_Config extends Config
32 {
38  var $config_vars = Array(
39  'SQ_HIPO_USE_SERVER' => Array('editable' => 1, 'default' => FALSE),
40  'SQ_HIPO_SERVER_STATUS_CHECK_THRESHOLD' => Array('editable' => 1, 'default' => 30),
41  'SQ_HIPO_TOTAL_THRESHOLD' => Array('editable' => 1, 'default' => 80),
42  );
43 
44 
49  function __construct()
50  {
51  parent::__construct();
52  $this->config_file = SQ_DATA_PATH.'/private/conf/hipo.inc';
53  $this->_loadJobConfigVars();
54 
55  }//end constructor
56 
57 
65  function _loadJobConfigVars()
66  {
67  // if our config file doesn't exist then we can't load the job's because they require it
68  if (!file_exists($this->config_file)) return;
69 
70  // ask each of the jobs for their config vars
71  $packages = $GLOBALS['SQ_SYSTEM']->getInstalledPackages();
72 
73  foreach($packages as $package) {
74  if ($package['code_name'] == '__core__') {
75  $hipo_job_path = SQ_SYSTEM_ROOT.'/core/hipo/jobs';
76  } else {
77  $hipo_job_path = SQ_SYSTEM_ROOT.'/packages/'.strtolower($package['code_name']).'/hipo_jobs';
78  }
79 
80  if (is_dir($hipo_job_path)) {
81  require_once SQ_FUDGE_PATH.'/general/file_system.inc';
82  $d = dir($hipo_job_path);
83  while (FALSE !== ($file = $d->read())) {
84  if ($file == '.' || $file == '..') {
85  continue;
86  }
87  // skip hidden files
88  if (strpos($file, '.') == 0) continue;
89 
90  if (!is_dir($hipo_job_path.'/'.$file)) {
91  if (get_file_type($file) != 'inc') continue;
92  require_once $hipo_job_path.'/'.$file;
93  $type_code = substr($file, 0, strpos($file, '.'));
94 
95  if ($type_code) {
96  $vars = call_user_func(Array($type_code, 'getConfigVars'));
97  $this->config_vars = array_merge($this->config_vars, $vars);
98  }
99  }
100  }//end while
101 
102  $d->close();
103 
104  }//end if
105 
106  }//end foreach
107 
108  }//end _loadJobConfigVars()
109 
110 
122  function save($vars, $backup_existing=FALSE)
123  {
124  // if the config file exists, just do a normal save
125  if (file_exists($this->config_file)) {
126  return parent::save($vars, $backup_existing);
127 
128  // else this is the first time that we have saved a config, things need to be done a little differently
129  } else {
130 
131  // first we save as normal, but we won't have the jobs config vars in there
132  // (no need to backup either because the file doesn't exist)
133  if (!parent::save($vars, FALSE)) return FALSE;
134  // then we load all jobs configs (which can happen now that there is a
135  // config file that they can require) and save again to put them in the file
136  $this->_loadJobConfigVars();
137  return parent::save($vars, FALSE);
138 
139  }//end if
140 
141  }//end save()
142 
143 
151  function canAcquireLock()
152  {
153  // need to be root
154  return $GLOBALS['SQ_SYSTEM']->userRoot();
155 
156  }//end canAcquireLock()
157 
158 
165  function writeAccess()
166  {
167  if (!parent::writeAccess()) return FALSE;
168  if (!$GLOBALS['SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS)) {
169  return TRUE;
170  }
171 
172  // need to be root
173  return $GLOBALS['SQ_SYSTEM']->userRoot();
174 
175  }//end writeAccess()
176 
177 
190  function paintBackend(&$o)
191  {
192  parent::paintBackend($o);
193 
194  $write_access = $this->writeAccess();
195  $class = get_class_lower($this);
196 
197  $o->openSection(translate('hipo_server_configuration'));
198 
199  // writing out standard fields, which are not specific to any single job
200  $o->openField(translate('run_on_squiz_server'));
201  if ($write_access) {
202  combo_box($class.'[SQ_HIPO_USE_SERVER]', Array('1' => translate('yes'), '0' => translate('no')), FALSE, SQ_HIPO_USE_SERVER);
203  } else {
204  echo (SQ_HIPO_USE_SERVER) ? translate('yes') : translate('no');
205  }
206  $o->closeField();
207 
208  // server check threshold config entry
209  $o->openField(translate('hipo_status_check_threshold'));
210  if ($write_access) {
211  text_box($class.'[SQ_HIPO_SERVER_STATUS_CHECK_THRESHOLD]', SQ_HIPO_SERVER_STATUS_CHECK_THRESHOLD, 5);
212  echo '&nbsp;';
213  } else {
214  echo SQ_HIPO_SERVER_STATUS_CHECK_THRESHOLD;
215  }
216  echo translate('hipo_status_check_threshold_note');
217  $o->closeField();
218 
219  // total threshold HIPO config entry
220  $o->openField(translate('hipo_freestyle_threashold'));
221  if ($write_access) {
222  text_box($class.'[SQ_HIPO_TOTAL_THRESHOLD]', SQ_HIPO_TOTAL_THRESHOLD, 5);
223  echo '&nbsp;';
224  } else {
225  echo SQ_HIPO_TOTAL_THRESHOLD;
226  }
227  echo translate('hipo_threshold_note');
228  $o->closeField();
229 
230  // looping through job class files and painting their backends
231  $this->paintJobsBackends($o, $class);
232 
233  $o->closeSection();
234 
235  if ($write_access) $o->commitButton('', TRUE);
236 
237  }//end paintBackend()
238 
239 
249  function paintJobsBackends(&$o, $class)
250  {
251  $packages = $GLOBALS['SQ_SYSTEM']->getInstalledPackages();
252 
253  foreach($packages as $package) {
254  if ($package['code_name'] == '__core__') {
255  $hipo_job_path = SQ_SYSTEM_ROOT.'/core/hipo/jobs';
256  } else {
257  $hipo_job_path = SQ_SYSTEM_ROOT.'/packages/'.$package['code_name'].'/hipo_jobs';
258  //include locale strings for hipo jobs because they are not assets and the strings are in package locale strings
259  $GLOBALS['SQ_SYSTEM']->lm->includePackageStrings($package['code_name']);
260  }
261 
262  if (is_dir($hipo_job_path)) {
263  $d = dir($hipo_job_path);
264 
265  while (FALSE !== ($file = $d->read())) {
266  if ($file == '.' || $file == '..') {
267  continue;
268  }
269  // skip hidden files
270  if (strpos($file, '.') == 0) continue;
271 
272  if (!is_dir($hipo_job_path.'/'.$file)) {
273  if (get_file_type($file) != 'inc') continue;
274  require_once $hipo_job_path.'/'.$file;
275  $type_code = substr($file, 0, strpos($file, '.'));
276 
277  $write_access = $this->writeAccess();
278  if ($type_code) {
279  eval($type_code.'::paintConfig($o, $class, $write_access);');
280  }
281  }
282  }//end while
283 
284  $d->close();
285 
286  }//end if
287 
288  }//end foreach
289 
290  }//end paintJobsBackends()
291 
292 
293 }//end class
294 
295 ?>