function UsageAndExit($oP) { $bModeCLI = utils::IsModeCLI(); if ($bModeCLI) { $oP->p("USAGE:\n"); $oP->p("php cron.php --auth_user=<login> --auth_pwd=<password> [--param_file=<file>] [--verbose=1] [--debug=1] [--status_only=1]\n"); } else { $oP->p("Optional parameters: verbose, param_file, status_only\n"); } $oP->output(); exit - 2; }
function UsageAndExit($oP) { global $aPageParams; $bModeCLI = utils::IsModeCLI(); if ($bModeCLI) { $oP->p("USAGE:\n"); $oP->p("php -q synchro_exec.php --auth_user=<login> --auth_pwd=<password> --data_sources=<comma_separated_list_of_data_sources> [max_chunk_size=<limit the count of replica loaded in a single pass>]\n"); } else { $oP->p("The parameter 'data_sources' is mandatory, and must contain a comma separated list of data sources\n"); } $oP->output(); exit - 2; }
function UsageAndExit($oP) { global $aPageParams; $bModeCLI = utils::IsModeCLI(); $oP->p("USAGE:\n"); foreach ($aPageParams as $sParam => $aParamData) { $aModes = explode(',', $aParamData['modes']); if ($bModeCLI) { if (in_array('cli', $aModes)) { $sDesc = $aParamData['description'] . ', ' . ($aParamData['mandatory'] ? 'mandatory' : 'optional, defaults to [' . $aParamData['default'] . ']'); $oP->p("{$sParam} = {$sDesc}"); } } else { if (in_array('http', $aModes)) { $sDesc = $aParamData['description'] . ', ' . ($aParamData['mandatory'] ? 'mandatory' : 'optional, defaults to [' . $aParamData['default'] . ']'); $oP->p("{$sParam} = {$sDesc}"); } } } $oP->output(); exit; }
require_once APPROOT . '/application/webpage.class.inc.php'; require_once APPROOT . '/application/csvpage.class.inc.php'; require_once APPROOT . '/application/clipage.class.inc.php'; require_once APPROOT . '/application/startup.inc.php'; function ReadMandatoryParam($oP, $sParam, $sSanitizationFilter = 'parameter') { $sValue = utils::ReadParam($sParam, null, true, $sSanitizationFilter); if (is_null($sValue)) { $oP->p("ERROR: Missing argument '{$sParam}'\n"); exit(29); } return trim($sValue); } ///////////////////////////////// // Main program if (!utils::IsModeCLI()) { $oP = new WebPage(Dict::S("TitleSynchroExecution")); $oP->p("This page is used internally by iTop"); $oP->output(); exit - 2; } $oP = new CLIPage(Dict::S("TitleSynchroExecution")); try { utils::UseParamFile(); } catch (Exception $e) { $oP->p("Error: " . $e->GetMessage()); $oP->output(); exit - 2; } // Next steps: // specific arguments: 'csvfile'
function InteractiveShell($sExpression, $sQueryId, $sFormat, $sFileName, $sMode) { if ($sMode == 'dialog') { $oP = new ajax_page(''); $oP->add('<div id="interactive_export_dlg">'); $sExportBtnLabel = json_encode(Dict::S('UI:Button:Export')); $sJSTitle = json_encode(htmlentities(utils::ReadParam('dialog_title', '', false, 'raw_data'), ENT_QUOTES, 'UTF-8')); $oP->add_ready_script(<<<EOF \t\t\$('#interactive_export_dlg').dialog({ \t\t\tautoOpen: true, \t\t\tmodal: true, \t\t\twidth: '80%', \t\t\ttitle: {$sJSTitle}, \t\t\tclose: function() { \$('#export-form').attr('data-state', 'cancelled'); \$(this).remove(); }, \t\t\tbuttons: [ \t\t\t\t{text: {$sExportBtnLabel}, id: 'export-dlg-submit', click: function() {} } \t\t\t] \t\t}); \t\t\t \t\tsetTimeout(function() { \$('#interactive_export_dlg').dialog('option', { position: { my: "center", at: "center", of: window }}); \$('#export-btn').hide(); ExportInitButton('#export-dlg-submit'); }, 100); EOF ); } else { $oP = new iTopWebPage('iTop Export'); } if ($sExpression === null) { // No expression supplied, let's check if phrasebook entry is given if ($sQueryId !== null) { $oSearch = DBObjectSearch::FromOQL('SELECT QueryOQL WHERE id = :query_id', array('query_id' => $sQueryId)); $oQueries = new DBObjectSet($oSearch); if ($oQueries->Count() > 0) { $oQuery = $oQueries->Fetch(); $sExpression = $oQuery->Get('oql'); $sFields = trim($oQuery->Get('fields')); } else { ReportErrorAndExit("Invalid query phrasebook identifier: '{$sQueryId}'"); } } else { if (utils::IsModeCLI()) { Usage(); ReportErrorAndExit("No expression or query phrasebook identifier supplied."); } else { // form to enter an OQL query or pick a query phrasebook identifier DisplayForm($oP, utils::GetAbsoluteUrlAppRoot() . 'webservices/export-v2.php', $sExpression, $sQueryId, $sFormat); $oP->output(); exit; } } } if ($sFormat !== null) { $oExporter = BulkExport::FindExporter($sFormat); if ($oExporter === null) { $aSupportedFormats = BulkExport::FindSupportedFormats(); ReportErrorAndExit("Invalid output format: '{$sFormat}'. The supported formats are: " . implode(', ', array_keys($aSupportedFormats))); } else { DisplayForm($oP, utils::GetAbsoluteUrlAppRoot() . 'webservices/export-v2.php', $sExpression, $sQueryId, $sFormat); } } else { DisplayForm($oP, utils::GetAbsoluteUrlAppRoot() . 'webservices/export-v2.php', $sExpression, $sQueryId, $sFormat); } if ($sMode == 'dialog') { $oP->add('</div>'); } $oP->output(); }
/** * Do the entire synchronization job */ protected function DoSynchronize() { $this->m_oStatLog->Set('status_curr_job', 1); $this->m_oStatLog->Set('status_curr_pos', -1); $iMaxChunkSize = utils::ReadParam('max_chunk_size', 0, true); if ($iMaxChunkSize > 0) { // Split the execution into several processes // Each process will call DoSynchronizeChunk() // The loop will end when a process does not reply "continue" on the last line of its output if (!utils::IsModeCLI()) { throw new SynchroExceptionNotStarted(Dict::S('Core:SyncSplitModeCLIOnly')); } $aArguments = array(); $aArguments['source'] = $this->m_oDataSource->GetKey(); $aArguments['log'] = $this->m_oStatLog->GetKey(); $aArguments['change'] = $this->m_oChange->GetKey(); $aArguments['chunk'] = $iMaxChunkSize; if ($this->m_oLastFullLoadStartDate) { $aArguments['last_full_load'] = $this->m_oLastFullLoadStartDate->Format('Y-m-d H:i:s'); } else { $aArguments['last_full_load'] = ''; } $this->m_oStatLog->DBUpdate($this->m_oChange); $iStepCount = 0; do { $aArguments['step_count'] = $iStepCount; $iStepCount++; list($iRes, $aOut) = utils::ExecITopScript('synchro/priv_sync_chunk.php', $aArguments); // Reload the log that has been modified by the processes $this->m_oStatLog->Reload(); $sLastRes = strtolower(trim(end($aOut))); switch ($sLastRes) { case 'continue': $bContinue = true; break; case 'finished': $bContinue = false; break; default: $this->m_oStatLog->AddTrace("The script did not reply with the expected keywords:"); $aIndentedOut = array(); foreach ($aOut as $sOut) { $aIndentedOut[] = "-> {$sOut}"; $this->m_oStatLog->AddTrace(">>> {$sOut}"); } throw new Exception("Encountered an error in an underspinned process:\n" . implode("\n", $aIndentedOut)); } } while ($bContinue); } else { $this->PrepareProcessing(); $this->DoJob1(); $this->DoJob2(); $this->DoJob3(); } }
$oP->add("Unsupported format '{$sFormat}'. Possible values are: html, csv, spreadsheet or xml."); } } } catch (Exception $e) { $oP = new WebPage("iTop - Export"); $oP->p("Error the query can not be executed."); if ($e instanceof CoreException) { $oP->p($e->GetHtmlDesc()); } else { $oP->p($e->getMessage()); } } } if (!$oP) { // Display a short message about how to use this page $bModeCLI = utils::IsModeCLI(); if ($bModeCLI) { $oP = new CLIPage("iTop - Export"); } else { $oP = new WebPage("iTop - Export"); } $oP->p("General purpose export page."); $oP->p("Parameters:"); $oP->p(" * expression: an OQL expression (URL encoded if needed)"); $oP->p(" * query: (alternative to 'expression') the id of an entry from the query phrasebook"); $oP->p(" * arg_xxx: (needed if the query has parameters) the value of the parameter 'xxx'"); $oP->p(" * format: (optional, default is html) the desired output format. Can be one of 'html', 'spreadsheet', 'csv', 'xlsx' or 'xml'"); $oP->p(" * fields: (optional, no effect on XML format) list of fields (attribute codes, or alias.attcode) separated by a coma"); $oP->p(" * fields_advanced: (optional, no effect on XML/HTML formats ; ignored is fields is specified) If set to 1, the default list of fields will include the external keys and their reconciliation keys"); $oP->p(" * filename: (optional, no effect in CLI mode) if set then the results will be downloaded as a file"); }
function Usage($oP) { $oP->p('Perform a backup of the iTop database by running mysqldump'); $oP->p('Parameters:'); if (utils::IsModeCLI()) { $oP->p('auth_user: login, must be administrator'); $oP->p('auth_pwd: ...'); } $oP->p('backup_file [optional]: name of the file to store the backup into. Follows the PHP strftime format spec. The following placeholders are available: __HOST__, __DB__, __SUBNAME__'); $oP->p('simulate [optional]: set to check the name of the file that would be created'); $oP->p('mysql_bindir [optional]: specify the path for mysqldump'); if (utils::IsModeCLI()) { $oP->p('Example: php -q backup.php --auth_user=admin --auth_pwd=myPassw0rd'); $oP->p('Known limitation: the current directory must be the directory of backup.php'); } else { $oP->p('Example: .../backup.php?backup_file=/tmp/backup.__DB__-__SUBNAME__.%Y-%m'); } }