public static function generate($tableName, array $updateIds = []) { if (!isset(self::$tables[$tableName])) { CLISetup::log('SqlGen::generate - invalid table given', CLISetup::LOG_ERROR); return false; } if (!empty(self::$tables[$tableName][0])) { $tbl = self::$tables[$tableName]; // shorthand CLISetup::log('SqlGen::generate() - copying ' . $tbl[0] . '.dbc into aowow_' . $tableName); $dbc = new DBC($tbl[0], CLISetup::$tmpDBC); if ($dbc->error) { return false; } $dbcData = $dbc->readArbitrary($tbl[1]); foreach ($dbcData as $row) { DB::Aowow()->query('REPLACE INTO ?_' . $tableName . ' (?#) VALUES (?a)', array_keys($row), array_values($row)); } return !!$dbcData; } else { if (file_exists('setup/tools/sqlgen/' . $tableName . '.func.php')) { $customData = $reqDBC = []; CLISetup::log('SqlGen::generate() - filling aowow_' . $tableName . ' with data'); require_once 'setup/tools/sqlgen/' . $tableName . '.func.php'; if (function_exists($tableName)) { // check for required auxiliary DBC files foreach ($reqDBC as $req) { if (!CLISetup::loadDBC($req)) { return false; } } $success = $tableName($updateIds); // apply post generator custom data foreach ($customData as $id => $data) { if ($data) { DB::Aowow()->query('UPDATE ?_' . $tableName . ' SET ?a WHERE id = ?d', $data, $id); } } } else { CLISetup::log(' - subscript \'' . $tableName . '\' not defined in included file', CLISetup::LOG_ERROR); } return $success; } else { CLISetup::log(sprintf(ERR_MISSING_INCL, $tableName, 'setup/tools/sqlgen/' . $tableName . '.func.php'), CLISetup::LOG_ERROR); } } }
public static function generate($key, array $updateIds = []) { $success = false; $reqDBC = []; if (file_exists('setup/tools/filegen/' . $key . '.func.php')) { require_once 'setup/tools/filegen/' . $key . '.func.php'; } else { if (empty(self::$tplFiles[$key])) { CLISetup::log(sprintf(ERR_MISSING_INCL, $key, 'setup/tools/filegen/' . $key . '.func.php', CLISetup::LOG_ERROR)); return false; } } CLISetup::log('FileGen::generate() - gathering data for ' . $key); if (!empty(self::$tplFiles[$key])) { list($file, $destPath, $deps) = self::$tplFiles[$key]; if ($content = file_get_contents(FileGen::$tplPath . $file . '.in')) { if ($dest = @fOpen($destPath . $file, "w")) { // replace constants $content = strtr($content, FileGen::$txtConstants); // check for required auxiliary DBC files foreach ($reqDBC as $req) { if (!CLISetup::loadDBC($req)) { continue 2; } } // must generate content // PH format: /*setup:<setupFunc>*/ $funcOK = true; if (preg_match_all('/\\/\\*setup:([\\w\\-_]+)\\*\\//i', $content, $m)) { foreach ($m[1] as $func) { if (function_exists($func)) { $content = str_replace('/*setup:' . $func . '*/', $func(), $content); } else { $funcOK = false; CLISetup::log('No function for was registered for placeholder ' . $func . '().', CLISetup::LOG_ERROR); if (!array_reduce(get_included_files(), function ($inArray, $itr) use($func) { return $inArray || false !== strpos($itr, $func); }, false)) { CLISetup::log('Also, expected include setup/tools/filegen/' . $name . '.func.php was not found.'); } } } } if (fWrite($dest, $content)) { CLISetup::log(sprintf(ERR_NONE, CLISetup::bold($destPath . $file)), CLISetup::LOG_OK); if ($content && $funcOK) { $success = true; } } else { CLISetup::log(sprintf(ERR_WRITE_FILE, CLISetup::bold($destPath . $file)), CLISetup::LOG_ERROR); } fClose($dest); } else { CLISetup::log(sprintf(ERR_CREATE_FILE, CLISetup::bold($destPath . $file)), CLISetup::LOG_ERROR); } } else { CLISetup::log(sprintf(ERR_READ_FILE, CLISetup::bold(FileGen::$tplPath . $file . '.in')), CLISetup::LOG_ERROR); } } else { if (!empty(self::$datasets[$key])) { if (function_exists($key)) { // check for required auxiliary DBC files foreach ($reqDBC as $req) { if (!CLISetup::loadDBC($req)) { return false; } } $success = $key($updateIds); } else { CLISetup::log(' - subscript \'' . $key . '\' not defined in included file', CLISetup::LOG_ERROR); } } } set_time_limit(FileGen::$defaultExecTime); // reset to default for the next script return $success; }