fogproject  1.5.9
About: FOG is a Linux-based network computer cloning solution for Windows, Mac OSX and various Linux distributions that ties together a few open-source tools with a PHP-based web interface. FOG doesn’t use any boot disks, or CDs; everything is done via TFTP and PXE.
  Fossies Dox: fogproject-1.5.9.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

schemaupdaterpage.class.php
Go to the documentation of this file.
1 <?php
23 {
29  public $node = 'schema';
37  public function __construct($name = '')
38  {
39  parent::__construct($name);
40  $schema = new Schema(1);
41  if ($schema->get('version') >= FOG_SCHEMA) {
42  self::redirect('index.php');
43  }
44  $this->name = 'Database Schema Installer / Updater';
45  $this->menu = array();
46  $this->subMenu = array();
47  }
53  public function index()
54  {
55  $this->title = _('Database Schema Installer / Updater');
56  $vals = array(
57  "\n",
58  );
59  // Success
60  echo '<div class="panel panel-info hiddeninitially" id="dbRunning">';
61  echo '<div class="panel-heading text-center">';
62  echo '<h4 class="title">';
63  echo _('Install/Update');
64  echo '</h4>';
65  echo '</div>';
66  echo '<div class="panel-body">';
67  echo '<div class="panel panel-warning">';
68  echo '<div class="panel-body">';
69  printf(
70  '%s %s %s %s %s (%s->%s->%s), %s %s.',
71  _('If you would like to backup your'),
72  _('FOG database you can do so using'),
73  _('MySQL Administrator or by running'),
74  _('the following command in a terminal'),
75  _('window'),
76  _('Applications'),
77  _('System Tools'),
78  _('Terminal'),
79  _('this will save the backup in your home'),
80  _('directory')
81  );
82  echo '<pre>';
83  echo 'mysqldump --allow-keywords -x -v fog > fogbackup.sql</p</pre>';
84  echo '</div>';
85  echo '</div>';
86  printf(
87  '%s, %s %s. %s, %s %s %s. %s, %s %s.',
88  _('Your FOG database schema is not up to date'),
89  _('either because you have updated'),
90  _('or this is a new FOG installation'),
91  _('If this is an upgrade'),
92  _('there will be a database backup stored on your'),
93  _('FOG server defaulting under the folder'),
94  '/home/fogDBbackups',
95  _('Should anything go wrong'),
96  _('this backup will enable you to return to the'),
97  _('previous install if needed')
98  );
99  echo '<br/>';
100  echo '<br/>';
101  printf(
102  '%s %s?',
103  _('Are you sure you wish to'),
104  _('install or update the FOG database')
105  );
106  echo '<br/>';
107  echo '<br/>';
108  echo '<form class="form-horizontal" action="'
109  . $this->formAction
110  . '" method="post">';
111  echo '<div class="col-xs-offset-4 col-xs-4">';
112  echo '<input type="hidden" name="fogverified"/>';
113  echo '<button type="submit" class="btn btn-primary btn-block" name='
114  . '"confirm">';
115  echo _('Install/Update Now');
116  echo '</button>';
117  echo '</div>';
118  echo '</form>';
119  echo '</div>';
120  echo '</div>';
121  // Failure
122  echo '<div class="panel panel-danger hiddeninitially" id="dbNotRunning">';
123  echo '<div class="panel-heading">';
124  echo '<h4 class="title">';
125  echo _('Database not available');
126  echo '</h4>';
127  echo '</div>';
128  echo '<div class="panel-body">';
129  printf(
130  '%s. %s. %s. %s %s%s%s. %s. %s, %s, %s.',
131  _('Your database connection appears to be invalid'),
132  _('FOG is unable to communicate with the database'),
133  _('There are many reasons why this could be the case'),
134  _('Please check your credentials in'),
135  dirname(dirname(__FILE__)),
136  DS,
137  'fog' . DS . 'config.class.php',
138  _('Also confirm that the database is indeed running'),
139  _('If credentials are correct'),
140  _('and if the Database service is running'),
141  _('check to ensure your filesystem has enough space')
142  );
143  echo '</div>';
144  echo '</div>';
145  }
151  public function indexPost()
152  {
153  if (!isset($_POST['fogverified'])) {
154  return;
155  }
156  if (!isset($_POST['confirm'])) {
157  return;
158  }
159  include sprintf(
160  '%s%scommons%sschema.php',
161  BASEPATH,
162  DS,
163  DS
164  );
165  $errors = array();
166  try {
167  if (!DatabaseManager::getLink()) {
168  throw new Exception(_('No connection available'));
169  }
170  if (count($this->schema) <= self::$mySchema) {
171  throw new Exception(_('Update not required!'));
172  }
173  $items = array_slice(
174  $this->schema,
175  self::$mySchema,
176  null,
177  true
178  );
179  $newSchema = self::getClass('Schema', 1);
180  foreach ((array)$items as $version => &$updates) {
181  foreach ((array)$updates as &$update) {
182  if (!$update) {
183  continue;
184  }
185  if (is_callable($update)) {
186  $result = $update();
187  if (is_string($result)) {
188  $errors[] = sprintf(
189  '<p><b>%s %s:</b>'
190  . ' %s<br/><br/><b>%s %s:</b>'
191  . ' <pre>%s</pre></p>'
192  . '<p><b>%s:</b>'
193  . ' <pre>%s</pre></p>',
194  _('Update'),
195  _('ID'),
196  $version + 1,
197  _('Function'),
198  _('Error'),
199  $result,
200  _('Function'),
201  print_r($update, 1)
202  );
203  unset($update);
204  break 2;
205  }
206  } elseif (false !== self::$DB->query($update)->error) {
207  $dups = array(
208  1050, // Can't drop not exist
209  1054, // Column not found.
210  1060, // Duplicate column name
211  1061, // Duplicate index/key name
212  1062, // Duplicate entry
213  1091 // Table not exist.
214  );
215  $err = self::$DB->errorCode;
216  if (in_array(self::$DB->errorCode, $dups)) {
217  continue;
218  }
219  $errors[] = sprintf(
220  '<p><b>%s %s:</b>'
221  . ' %s<br/><br/><b>%s %s:</b>'
222  . ' <pre>%s</pre></p>'
223  . '<p><b>%s:</b>'
224  . ' <pre>%s</pre></p>'
225  . '<p><b>%s:</b>'
226  . ' <pre>%s</pre></p>',
227  _('Update'),
228  _('ID'),
229  $version + 1,
230  _('Database'),
231  _('Error'),
232  self::$DB->error,
233  _('Variable contains'),
234  print_r($this->schema[$version], 1),
235  _('Database SQL'),
236  $update
237  );
238  unset($update);
239  break 2;
240  }
241  unset($update);
242  }
243  $newSchema->set('version', $version + 1);
244  unset($updates);
245  }
246  if (!$newSchema->save()
247  || count($errors) > 0
248  ) {
249  $fatalerrmsg = '';
250  $fatalerrmsg = sprintf(
251  '<p>%s</p>',
252  _('Install / Update Failed!')
253  );
254  if (count($errors)) {
255  $fatalerrmsg .= sprintf(
256  '<h2>%s</h2>%s',
257  _('The following errors occurred'),
258  implode('<hr/>', $errors)
259  );
260  }
261  throw new Exception($fatalerrmsg);
262  }
263  $db = self::$DB->returnThis();
264  self::$DB->currentDb($db);
265  $text = sprintf(
266  '<p>%s</p><p>%s <a href="index.php">%s</a> %s</p>',
267  _('Install / Update Successful!'),
268  _('Click'),
269  _('here'),
270  _('to login')
271  );
272  if (count($errors)) {
273  $text = sprintf(
274  '<h2>%s</h2>%s',
275  _('The following errors occured'),
276  implode('<hr/>', $errors)
277  );
278  }
279  if (self::$ajax) {
280  echo json_encode($text);
281  exit;
282  }
283  echo $text;
284  } catch (Exception $e) {
285  printf('<p>%s</p>', $e->getMessage());
286  http_response_code(404);
287  }
288  }
289 }
SchemaUpdaterPage\__construct
__construct($name='')
Definition: schemaupdaterpage.class.php:37
SchemaUpdaterPage\indexPost
indexPost()
Definition: schemaupdaterpage.class.php:151
exit
exit
Definition: download.php:102
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
Schema
Definition: schema.class.php:23
DatabaseManager\getLink
static getLink()
Definition: databasemanager.class.php:172
SchemaUpdaterPage\$node
$node
Definition: schemaupdaterpage.class.php:29
FOGBase\error
static error($txt, $data=array())
Definition: fogbase.class.php:721
SchemaUpdaterPage
Definition: schemaupdaterpage.class.php:23
$items
$items
Definition: boot.php:24
FOGPage\$name
$name
Definition: fogpage.class.php:31
schema
$this schema[]
Definition: schema.php:25
FOGBase\redirect
static redirect($url='')
Definition: fogbase.class.php:831
FOGPage
Definition: fogpage.class.php:25
SchemaUpdaterPage\index
index()
Definition: schemaupdaterpage.class.php:53