+<?php
+
+
+
+require_once 'Pman.php';
+class Pman_Core_UpdateDatabase extends Pman
+{
+
+ static $cli_desc = "Update SQL - Beta";
+
+
+
+ var $cli = false;
+ function getAuth() {
+
+
+ $ff = HTML_FlexyFramework::get();
+ if (!empty($ff->cli)) {
+ $this->cli = true;
+ return true;
+ }
+
+ parent::getAuth(); // load company!
+ $au = $this->getAuthUser();
+ if (!$au || $au->company()->comptype != 'OWNER') {
+ $this->jerr("Not authenticated", array('authFailure' => true));
+ }
+ $this->authUser = $au;
+ return true;
+ }
+
+ function get()
+ {
+ $this->importSQL();
+
+ }
+ function output() {
+ return '';
+ }
+ /**
+ * imports SQL files from all DataObjects directories....
+ *
+ * except any matching /migrate/
+ */
+ function importSQL()
+ {
+
+ $ff = HTML_Flexyframework::get();
+
+ $url = parse_url($ff->DB_DataObject['database']);
+ // hide stuff for web..
+
+ require_once 'System.php';
+ $cat = System::which('cat');
+ $mysql = System::which('mysql');
+
+ $ar = $this->modulesList();
+
+
+ $mysql_cmd = $mysql .
+ ' -h ' . $url['host'] .
+ ' -u' . escapeshellarg($url['user']) .
+ (!empty($url['pass']) ? ' -p' . escapeshellarg($url['pass']) : '') .
+ ' ' . basename($url['path']);
+ echo $mysql_cmd . "\n" ;
+
+
+
+
+ foreach($ar as $m) {
+
+ $fd = $this->rootDir. "/Pman/$m/DataObjects";
+
+ foreach(glob($fd.'/*.sql') as $fn) {
+
+
+ if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
+ continue;
+ }
+
+ $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ;
+
+ echo $cmd. ($this->cli ? "\n" : "<BR>\n");
+
+ passthru($cmd);
+
+
+ }
+ }
+
+
+
+ }
+
+}
\ No newline at end of file