示例#1
0
 function __construct($structure = null)
 {
     $path = expandpath('app:' . $structure);
     if (file_exists($path) && $structure) {
         $strx = domdocument::load($path);
         $domx = new DOMXpath($strx);
         $cfgs = $domx->query('/configurationschema/config');
         foreach ($cfgs as $item) {
             $key = $item->getAttribute('key');
             if ($item->hasAttribute('type')) {
                 $vartype = $item->getAttribute('type');
             } else {
                 $vartype = 'string';
             }
             $description = null;
             $default = null;
             if ($item->childNodes->length > 0) {
                 foreach ($item->childNodes as $item) {
                     switch ($item->nodeName) {
                         case 'default':
                             $value = $item->getAttribute('value');
                             $type = $item->getAttribute('type');
                             if ($type == 'string') {
                                 $value = str_replace('${servername}', request::getDomain(), $value);
                                 $default = $value;
                             }
                             if ($type == 'integer') {
                                 $value = intval($value);
                                 $default = $value;
                             }
                             if ($type == 'float') {
                                 $value = floatval($value);
                                 $default = $value;
                             }
                             if ($type == 'generate') {
                                 if ($value == 'uuid') {
                                     $default = uuid::v4();
                                 } else {
                                     $default = '<unknown>';
                                 }
                             }
                             break;
                         case 'description':
                             $description = $item->nodeValue;
                             break;
                     }
                 }
             }
             if (!arr::hasKey($this->data, $key)) {
                 $this->data[$key] = $default;
             }
             $this->defs[$key] = array('description' => $description, 'vartype' => $vartype);
         }
         $this->flush();
     }
 }
示例#2
0
 public function export()
 {
     console::writeLn(__astr('\\b{Exporting tables and data}'));
     $db = new DatabaseConnection();
     $args = func_get_args();
     if (count($args) == 0) {
         $args[] = '%';
     }
     $drop = false;
     $data = false;
     foreach ($args as $arg) {
         try {
             if (strtolower($arg) == 'drop') {
                 $drop = true;
             } elseif (strtolower($arg) == 'data') {
                 $data = true;
             } else {
                 $tbl = $db->getRows("SHOW TABLES LIKE %s", $arg);
                 foreach ($tbl as $tblc) {
                     $c = $tblc[0];
                     console::write("  [app] %-30s ", $c);
                     // Get the create table syntax
                     $crs = $db->getSingleRow("SHOW CREATE TABLE " . $c);
                     $sqlcreate = $crs;
                     // Get the data
                     $fsql = fopen(expandpath('app:/sql/' . $c . '.sql'), 'w');
                     if ($drop) {
                         fputs($fsql, "DROP TABLE IF EXISTS " . $c . ";\n");
                     }
                     fputs($fsql, $crs[1] . "\n");
                     fclose($fsql);
                     console::write("SQL ");
                     if ($data) {
                         // Export the data as well
                         $drs = $db->getRows("SELECT * FROM " . $c);
                         foreach ($drs[0] as $k => $v) {
                             if ($k != '0' && intval($k) == 0) {
                                 $hdr[] = $k;
                             }
                         }
                         $fdat = fopen(expandpath('app:/sql/' . $c . '.csv'), 'w');
                         fputcsv($fdat, $hdr, ";", '"');
                         foreach ($drs as $row) {
                             $dout = array();
                             foreach ($row as $i => $h) {
                                 if ($i != '0' && intval($i) == 0) {
                                     $dout[] = $h;
                                 }
                             }
                             fputcsv($fdat, $dout, ";");
                         }
                         fclose($fdat);
                         console::write("CSV ");
                     }
                     console::writeLn();
                 }
             }
         } catch (DatabaseException $e) {
             console::writeLn();
             console::warn($e->getMessage());
         }
     }
 }