本文整理汇总了PHP中Timer::getTime方法的典型用法代码示例。如果您正苦于以下问题:PHP Timer::getTime方法的具体用法?PHP Timer::getTime怎么用?PHP Timer::getTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer::getTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatchLoopShutdown
public function dispatchLoopShutdown()
{
//
// Force output to be sent - we need the client to have the page before
// we start flushing progress bar updates
//
$app = AppController::getInstance();
$req = $app->getRequest();
$resp = $app->getResponse();
$resp->sendResponse();
$resp->clearContent();
//
// Do reindexing
//
if ($req->isLoggedIn() && $req->user->canDoAction('can_do_search_reindex')) {
set_time_limit(3600 * 8);
$o_db = new Db();
$t_timer = new Timer();
$o_dm = Datamodel::load();
$va_table_names = $o_dm->getTableNames();
$vn_tc = 0;
foreach ($va_table_names as $vs_table) {
if ($o_instance = $o_dm->getInstanceByTableName($vs_table)) {
if ($o_instance->isHierarchical()) {
if (!$o_instance->rebuildAllHierarchicalIndexes()) {
$o_instance->rebuildHierarchicalIndex();
}
}
caIncrementHierachicalReindexProgress(_t('Rebuilding hierarchical index for %1', $o_instance->getProperty('NAME_PLURAL')), $t_timer->getTime(2), memory_get_usage(true), $va_table_names, $o_instance->tableNum(), $o_instance->getProperty('NAME_PLURAL'), $vn_tc + 1);
}
$vn_tc++;
}
caIncrementHierachicalReindexProgress(_t('Index rebuild complete!'), $t_timer->getTime(2), memory_get_usage(true), $va_table_names, null, null, sizeof($va_table_names));
}
}
示例2: parse
function parse()
{
if ($this->doParseRSS) {
require_once "include/domit_rss/timer.php";
$timer = new Timer();
$success = false;
$timer->start();
if (!defined('DOMIT_RSS_INCLUDE_PATH')) {
define('DOMIT_RSS_INCLUDE_PATH', dirname(__FILE__) . "/");
}
switch ($this->rssparser) {
case "domit_rss_lite":
require_once DOMIT_RSS_INCLUDE_PATH . 'xml_domit_rss_lite.php';
$this->rssdoc = new xml_domit_rss_document_lite($this->rssurl);
break;
case "domit_rss":
require_once DOMIT_RSS_INCLUDE_PATH . 'xml_domit_rss.php';
$this->rssdoc = new xml_domit_rss_document($this->rssurl);
break;
}
// switch
$timer->stop();
$this->displayNew();
echo "<br /><br />Time elapsed: " . $timer->getTime() . "seconds<br /><br />\n";
}
}
示例3: parse
function parse()
{
if ($this->xmlaction != null) {
require_once "timer.php";
$timer = new Timer();
$success = false;
$this->saxparser == "saxy" ? $parseSAXY = true : ($parseSAXY = false);
$timer->start();
switch ($this->domparser) {
case "domit":
//change this to the domit path
require_once 'xml_domit_parser.php';
$this->xmldoc =& new DOMIT_Document();
$this->xmldoc->expandEmptyElementTags(true);
$this->xmldoc->setNamespaceAwareness(true);
break;
case "domitlite":
//change this to the domit lite path
require_once 'xml_domit_lite_parser.php';
$this->xmldoc =& new DOMIT_Lite_Document();
break;
}
// switch
switch ($this->xmlaction) {
case "parsefile":
$success = $this->xmldoc->loadXML($this->xmlfile, $parseSAXY);
break;
case "parseurl":
$success = $this->xmldoc->loadXML("http://" . $this->xmlurl, $parseSAXY);
break;
case "parsetext":
$success = $this->xmldoc->parseXML($this->xmltext, $parseSAXY);
break;
}
$timer->stop();
if ($success) {
echo "<br /><br />Time elapsed: " . $timer->getTime() . "seconds<br /><br />\n";
if ($this->xmloutput == "tostring") {
echo $this->xmldoc->toString(true);
} else {
if ($this->xmloutput == "tonormalizedstring") {
echo $this->xmldoc->toNormalizedString(true);
} else {
if ($this->xmloutput == "toarray") {
echo "<pre>\n";
print_r($this->xmldoc->toArray());
echo "</pre>\n";
}
}
}
} else {
echo "<br /><br />Parsing error: xml document may be invalid or malformed.\n";
}
}
}
示例4: die
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Ocsinventoryng plugin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ocsinventoryng. If not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------------------------------------------------------------------------------- */
// Ensure current directory when run from crontab
chdir(dirname($_SERVER["SCRIPT_FILENAME"]));
include '../../../inc/includes.php';
ini_set('display_errors', 1);
restore_error_handler();
if (!isset($_SERVER['argv'][1])) {
die("usage testsync.php <computerid>\n");
}
$link = new PluginOcsinventoryngOcslink();
if (!$link->getFromDBforComputer($_SERVER['argv'][1])) {
die("unknow computer\n");
}
printf("Device: %s\n", $link->getField('ocs_deviceid'));
$timer = new Timer();
$timer->start();
$prof = new XHProf("OCS sync");
PluginOcsinventoryngOcsServer::updateComputer($link->getID(), $link->getField('plugin_ocsinventoryng_ocsservers_id'), 1, 1);
unset($prof);
printf("Done in %s\n", $timer->getTime());
示例5: reindex
/**
* Forces a full reindex of all rows in the database or, optionally, a single table
*
* @param array $pa_table_names
* @param array $pa_options Reindexing options:
* showProgress
* interactiveProgressDisplay
* log
* callback
* @return null|false
*/
public function reindex($pa_table_names = null, $pa_options = null)
{
define('__CollectiveAccess_IS_REINDEXING__', 1);
$t_timer = new Timer();
$pb_display_progress = isset($pa_options['showProgress']) ? (bool) $pa_options['showProgress'] : true;
$pb_interactive_display = isset($pa_options['interactiveProgressDisplay']) ? (bool) $pa_options['interactiveProgressDisplay'] : false;
$ps_callback = isset($pa_options['callback']) ? (string) $pa_options['callback'] : false;
if ($pa_table_names) {
if (!is_array($pa_table_names)) {
$pa_table_names = array($pa_table_names);
}
$va_table_names = array();
foreach ($pa_table_names as $vs_table) {
if ($this->opo_datamodel->tableExists($vs_table)) {
$vn_num = $this->opo_datamodel->getTableNum($vs_table);
if ($pb_display_progress) {
print "\nTRUNCATING {$vs_table}\n\n";
}
$this->opo_engine->truncateIndex($vn_num);
$t_instance = $this->opo_datamodel->getInstanceByTableName($vs_table, true);
$va_table_names[$vn_num] = array('name' => $vs_table, 'num' => $vn_num, 'displayName' => $t_instance->getProperty('NAME_PLURAL'));
}
}
if (!sizeof($va_table_names)) {
return false;
}
} else {
// full reindex
$this->opo_engine->truncateIndex();
$va_table_names = $this->getIndexedTables();
}
$o_db = $this->opo_db;
if ($pb_display_progress || $ps_callback) {
$va_names = array();
foreach ($va_table_names as $vn_table_num => $va_table_info) {
$va_names[] = $va_table_info['displayName'];
}
if ($pb_display_progress) {
print "\nWILL INDEX [" . join(", ", $va_names) . "]\n\n";
}
}
$vn_tc = 0;
foreach ($va_table_names as $vn_table_num => $va_table_info) {
$vs_table = $va_table_info['name'];
$t_table_timer = new Timer();
$t_instance = $this->opo_datamodel->getInstanceByTableName($vs_table, true);
$vs_table_pk = $t_instance->primaryKey();
$vn_table_num = $t_instance->tableNum();
$va_fields_to_index = $this->getFieldsToIndex($vn_table_num);
if (!is_array($va_fields_to_index) || sizeof($va_fields_to_index) == 0) {
continue;
}
$qr_all = $o_db->query("SELECT " . $t_instance->primaryKey() . " FROM {$vs_table}");
$vn_num_rows = $qr_all->numRows();
if ($pb_display_progress) {
print CLIProgressBar::start($vn_num_rows, _t('Indexing %1', $t_instance->getProperty('NAME_PLURAL')));
}
$vn_c = 0;
$va_ids = $qr_all->getAllFieldValues($t_instance->primaryKey());
$va_element_ids = null;
if (method_exists($t_instance, "getApplicableElementCodes")) {
$va_element_ids = array_keys($t_instance->getApplicableElementCodes(null, false, false));
}
$vn_table_num = $t_instance->tableNum();
$vs_table_pk = $t_instance->primaryKey();
$va_field_data = array();
$va_intrinsic_list = $this->getFieldsToIndex($vs_table, $vs_table, array('intrinsicOnly' => true));
$va_intrinsic_list[$vs_table_pk] = array();
foreach ($va_ids as $vn_i => $vn_id) {
if (!($vn_i % 200)) {
// Pre-load attribute values for next 200 items to index; improves index performance
$va_id_slice = array_slice($va_ids, $vn_i, 200);
if ($va_element_ids) {
ca_attributes::prefetchAttributes($o_db, $vn_table_num, $va_id_slice, $va_element_ids);
}
$qr_field_data = $o_db->query("\n\t\t\t\t\t\tSELECT " . join(", ", array_keys($va_intrinsic_list)) . " \n\t\t\t\t\t\tFROM {$vs_table}\n\t\t\t\t\t\tWHERE {$vs_table_pk} IN (?)\t\n\t\t\t\t\t", array($va_id_slice));
$va_field_data = array();
while ($qr_field_data->nextRow()) {
$va_field_data[(int) $qr_field_data->get($vs_table_pk)] = $qr_field_data->getRow();
}
}
$this->indexRow($vn_table_num, $vn_id, $va_field_data[$vn_id], true, null, array(), array());
if ($pb_display_progress && $pb_interactive_display) {
CLIProgressBar::setMessage("Memory: " . caGetMemoryUsage());
print CLIProgressBar::next();
}
if ($ps_callback && !($vn_c % 100)) {
$ps_callback($vn_c, $vn_num_rows, null, null, (double) $t_timer->getTime(2), memory_get_usage(true), $va_table_names, $vn_table_num, $t_instance->getProperty('NAME_PLURAL'), $vn_tc + 1);
}
//.........这里部分代码省略.........
示例6: caLoadULAN
//.........这里部分代码省略.........
switch ($o_xml->nodeType) {
case XMLReader::ELEMENT:
$o_xml->read();
$va_subject['related_subjects'][] = $o_xml->value;
break;
}
break;
# ---------------------------
}
}
$o_xml->close();
}
$o_log->logInfo("Begin linking ULAN terms in hierarchy");
print "\n\nLINKING TERMS IN HIERARCHY...\n";
$vn_last_message_length = 0;
$t_list = new ca_lists();
$t_item = new ca_list_items();
$t_item->setMode(ACCESS_WRITE);
$vn_list_root_id = $t_list->getRootListItemID($vn_list_id);
foreach ($va_parent_child_links as $vs_child_id => $vs_parent_id) {
print str_repeat(chr(8), $vn_last_message_length);
$vs_message = "\tLINKING {$vs_child_id} to parent {$vs_parent_id}";
if (($vn_l = 100 - strlen($vs_message)) < 1) {
$vn_l = 1;
}
$vs_message .= str_repeat(' ', $vn_l);
$vn_last_message_length = strlen($vs_message);
print $vs_message;
if (in_array($vs_parent_id, array('500000000', '500000001'))) {
if (!$t_item->load($vn_child_item_id)) {
$o_log->logError("Could not load item for {$vs_child_id} (was translated to item_id={$vn_child_item_id})");
continue;
}
$t_item->set('parent_id', $vn_list_root_id);
$t_item->update(array('dontCheckCircularReferences' => true, 'dontSetHierarchicalIndexing' => true));
if ($t_item->numErrors()) {
$o_log->logError("Could not set parent_id for {$vs_child_id} to root): " . join('; ', $t_item->getErrors()));
continue;
}
$va_ulan_id_to_item_id[$vs_parent_id] = $vn_list_root_id;
}
if (!($vn_child_item_id = $va_ulan_id_to_item_id[$vs_child_id])) {
$o_log->logError("No list item id for child_id {$vs_child_id} (were there previous errors?)");
continue;
}
if (!($vn_parent_item_id = $va_ulan_id_to_item_id[$vs_parent_id])) {
$o_log->logError("No list item id for parent_id {$vs_parent_id} (were there previous errors?)");
continue;
}
if (!$t_item->load($vn_child_item_id)) {
$o_log->logError("Could not load item for {$vs_child_id} (was translated to item_id={$vn_child_item_id})");
continue;
}
$t_item->set('parent_id', $vn_parent_item_id);
$t_item->update(array('dontCheckCircularReferences' => true, 'dontSetHierarchicalIndexing' => true));
if ($t_item->numErrors()) {
$o_log->logError("Could not set parent_id for {$vs_child_id} (was translated to item_id={$vn_child_item_id}): " . join('; ', $t_item->getErrors()));
}
}
if ($vn_list_item_relation_type_id_related > 0) {
$o_log->logInfo("Begin adding ULAN related term links");
$vn_last_message_length = 0;
$t_item = new ca_list_items();
$t_link = new ca_list_items_x_list_items();
$t_link->setMode(ACCESS_WRITE);
foreach ($va_item_item_links as $vs_left_id => $vs_right_id) {
print str_repeat(chr(8), $vn_last_message_length);
$vs_message = "\tLINKING {$vs_left_id} to {$vs_right_id}";
if (($vn_l = 100 - strlen($vs_message)) < 1) {
$vn_l = 1;
}
$vs_message .= str_repeat(' ', $vn_l);
$vn_last_message_length = strlen($vs_message);
print $vs_message;
if (!($vn_left_item_id = $va_ulan_id_to_item_id[$vs_left_id])) {
$o_log->logError("No list item id for left_id {$vs_left_id} (were there previous errors?)");
continue;
}
if (!($vn_right_item_id = $va_ulan_id_to_item_id[$vs_right_id])) {
$o_log->logError("No list item id for right_id {$vs_right_id} (were there previous errors?)");
continue;
}
$t_link->set('term_left_id', $vn_left_item_id);
$t_link->set('term_right_id', $vn_right_item_id);
$t_link->set('type_id', $vn_list_item_relation_type_id_related);
$t_link->insert();
if ($t_link->numErrors()) {
$o_log->logError("Could not set link between {$vs_left_id} (was translated to item_id={$vn_left_item_id}) and {$vs_right_id} (was translated to item_id={$vn_right_item_id}): " . join('; ', $t_link->getErrors()));
}
}
} else {
$o_log->logWarn("Skipped import of term-term relationships because the ca_list_items_x_list_items 'related' relationship type is not defined for your installation");
}
$vn_duration = $t->getTime(1);
$vs_time = caFormatInterval($vn_duration);
$o_log->logInfo("Rebuilding hierarchical indices...");
$t_item->rebuildAllHierarchicalIndexes();
$o_log->logInfo("ULAN import complete. Took {$vs_time} ({$vn_duration})");
print "\n\nIMPORT COMPLETE. Took {$vs_time} ({$vn_duration})\n";
}
示例7: caIncrementProgress
caIncrementProgress($vn_progress, "Creating logins");
$va_login_info = $vo_installer->processLogins();
$vn_progress += 7;
caIncrementProgress($vn_progress, "Processing user interfaces");
$vo_installer->processUserInterfaces();
$vn_progress += 7;
caIncrementProgress($vn_progress, "Processing displays");
$vo_installer->processDisplays();
$vn_progress += 7;
caIncrementProgress($vn_progress, "Processing search forms");
$vo_installer->processSearchForms();
$vn_progress += 7;
caIncrementProgress($vn_progress, "Setting up hierarchies");
$vo_installer->processMiscHierarchicalSetup();
caIncrementProgress(100, "Installation complete");
$vs_time = "(Installation took " . $t_total->getTime(0) . " seconds)";
if ($vo_installer->numErrors()) {
$va_errors = array();
foreach ($vo_installer->getErrors() as $vs_err) {
$va_errors[] = "<li>{$vs_err}</li>";
}
caSetMessage("<div class='contentFailure'><div class='contentFailureHead'>There were errors during installation:</div><ul>" . join("", $va_errors) . "</ul><br/>{$vs_time}</div>");
} else {
$vs_message = "<div class='contentSuccess'><span style='font-size:18px;'><b>Installation was successful!</b></span><br/>You can now <a href='../index.php?action=login'>login</a> with ";
if (sizeof($va_login_info) == 1) {
foreach ($va_login_info as $vs_user_name => $vs_password) {
$vs_message .= "username <span class='contentHighlight'>{$vs_user_name}</span> and password <span class='contentHighlight'>{$vs_password}</span>.<br/><b>Make a note of this password!</b><br/>";
}
} else {
$vs_message .= " the following logins:<br/>";
foreach ($va_login_info as $vs_user_name => $vs_password) {
示例8: query
/**
* Execute a MySQL query
*
* @param $query Query to execute
*
* @return Query result handler
**/
function query($query)
{
global $CFG_GLPI, $DEBUG_SQL, $SQL_TOTAL_REQUEST;
if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE && $CFG_GLPI["debug_sql"]) {
$SQL_TOTAL_REQUEST++;
$DEBUG_SQL["queries"][$SQL_TOTAL_REQUEST] = $query;
$TIMER = new Timer();
$TIMER->start();
}
$res = @$this->dbh->query($query);
if (!$res) {
// no translation for error logs
$error = " *** MySQL query error:\n SQL: " . addslashes($query) . "\n Error: " . $this->dbh->error . "\n";
$error .= toolbox::backtrace(false, 'DBmysql->query()', array('Toolbox::backtrace()'));
Toolbox::logInFile("sql-errors", $error);
if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE && $CFG_GLPI["debug_sql"]) {
$DEBUG_SQL["errors"][$SQL_TOTAL_REQUEST] = $this->error();
}
}
if ($_SESSION['glpi_use_mode'] == Session::DEBUG_MODE && $CFG_GLPI["debug_sql"]) {
$TIME = $TIMER->getTime();
$DEBUG_SQL["times"][$SQL_TOTAL_REQUEST] = $TIME;
}
return $res;
}
示例9: install
//.........这里部分代码省略.........
return false;
}
$vs_profile_directory = $po_opts->getOption('profile-directory');
$vs_profile_directory = $vs_profile_directory ? $vs_profile_directory : __CA_BASE_DIR__ . '/install/profiles/xml';
$t_total = new Timer();
// If we are installing, then use Installer, otherwise use Updater
$vo_installer = null;
if ($pb_installing) {
$vo_installer = new Installer($vs_profile_directory, $po_opts->getOption('profile-name'), $po_opts->getOption('admin-email'), $po_opts->getOption('overwrite'), $po_opts->getOption('debug'));
} else {
$vo_installer = new Updater($vs_profile_directory, $po_opts->getOption('profile-name'), null, false, $po_opts->getOption('debug'));
}
$vb_quiet = $po_opts->getOption('quiet');
// if profile validation against XSD failed, we already have an error here
if ($vo_installer->numErrors()) {
CLIUtils::addError(_t("There were errors parsing the profile(s): %1", "\n * " . join("\n * ", $vo_installer->getErrors())));
return false;
}
if ($pb_installing) {
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Performing preinstall tasks"));
}
$vo_installer->performPreInstallTasks();
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Loading schema"));
}
$vo_installer->loadSchema();
if ($vo_installer->numErrors()) {
CLIUtils::addError(_t("There were errors loading the database schema: %1", "\n * " . join("\n * ", $vo_installer->getErrors())));
return false;
}
}
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Processing locales"));
}
$vo_installer->processLocales();
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Processing lists"));
}
$vo_installer->processLists();
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Processing relationship types"));
}
$vo_installer->processRelationshipTypes();
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Processing metadata elements"));
}
$vo_installer->processMetadataElements();
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Processing metadata dictionary"));
}
$vo_installer->processMetadataDictionary();
if (!$po_opts->getOption('skip-roles')) {
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Processing access roles"));
}
$vo_installer->processRoles();
}
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Processing user groups"));
}
$vo_installer->processGroups();
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Processing user logins"));
}
$va_login_info = $vo_installer->processLogins();
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Processing user interfaces"));
}
$vo_installer->processUserInterfaces();
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Processing displays"));
}
$vo_installer->processDisplays();
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Processing search forms"));
}
$vo_installer->processSearchForms();
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Setting up hierarchies"));
}
$vo_installer->processMiscHierarchicalSetup();
if (!$vb_quiet) {
CLIUtils::addMessage(_t("Installation complete"));
}
$vs_time = _t("Installation took %1 seconds", $t_total->getTime(0));
if ($vo_installer->numErrors()) {
CLIUtils::addError(_t("There were errors during installation: %1\n(%2)", "\n * " . join("\n * ", $vo_installer->getErrors()), $vs_time));
return false;
}
if ($pb_installing) {
CLIUtils::addMessage(_t("Installation was successful!\n\nYou can now login with the following logins: %1\nMake a note of these passwords!", "\n * " . join("\n * ", array_map(function ($username, $password) {
return _t("username %1 and password %2", $username, $password);
}, array_keys($va_login_info), array_values($va_login_info)))));
} else {
CLIUtils::addMessage(_t("Update of installation profile successful"));
}
CLIUtils::addMessage($vs_time);
return true;
}
示例10: execute
/**
* Executes a SQL statement
*
* @param mixed $po_caller object representation of the calling class, usually Db()
* @param DbStatement $opo_statement
* @param string $ps_sql SQL statement
* @param array $pa_values array of placeholder replacements
*/
public function execute($po_caller, $opo_statement, $ps_sql, $pa_values)
{
if (!$ps_sql) {
$opo_statement->postError(240, _t("Query is empty"), "Db->pdo_mysql->execute()");
return false;
}
$va_placeholder_map = $po_caller->getOption('placeholder_map');
$vs_sql = $ps_sql;
$va_proc_values = array();
$va_values_rev = array_reverse(array_keys($pa_values));
foreach ($va_values_rev as $vn_i) {
if (is_array($pa_values[$vn_i])) {
foreach ($pa_values[$vn_i] as $vn_x => $vs_vx) {
$pa_values[$vn_i][$vn_x] = $this->autoQuote($vs_vx);
}
$vs_str = join(",", $pa_values[$vn_i]);
$vs_sql = substr_replace($vs_sql, $vs_str, $va_placeholder_map[$vn_i], 1);
continue;
}
$va_proc_values[] = $pa_values[$vn_i];
}
if (sizeof($va_proc_values) != sizeof($pa_values)) {
$pa_values = array_reverse($va_proc_values);
$vo_dbstatement = $this->prepare($po_caller, $vs_sql);
$opo_statement = $vo_dbstatement->getOption('native_statement');
}
if (Db::$monitor) {
$t = new Timer();
}
if (!$opo_statement->execute(is_array($pa_values) && sizeof($pa_values) ? array_values($pa_values) : null)) {
$va_err = $this->opr_db->errorCode();
$po_caller->postError($this->nativeToDbError($this->opr_db->errorCode()), $va_err[2] . (__CA_ENABLE_DEBUG_OUTPUT__ ? "\n<pre>" . caPrintStacktrace() . "</pre>" : ""), "Db->pdo_mysql->execute()");
return false;
}
if (Db::$monitor) {
Db::$monitor->logQuery($vs_sql, $pa_values, $t->getTime(4), $opo_statement->rowCount());
}
return new DbResult($this, $opo_statement);
}
示例11: execute
/**
* Executes a SQL statement
*
* @param mixed $po_caller object representation of the calling class, usually Db()
* @param PDOStatement $opo_statement
* @param string $ps_sql SQL statement
* @param array $pa_values array of placeholder replacements
* @return bool|DbResult
*/
public function execute($po_caller, $opo_statement, $ps_sql, $pa_values)
{
if (!$ps_sql) {
$po_caller->postError(240, _t("Query is empty"), "Db->pdo_mysql->execute()");
return false;
}
if (!$opo_statement instanceof PDOStatement) {
$po_caller->postError(250, _t("Invalid prepared statement"), "Db->pdo_mysql->execute()");
return false;
}
if (!is_array($va_tmp = self::rewriteQueryAndParams($ps_sql, $pa_values))) {
$po_caller->postError(250, _t("Query rewrite failed"), "Db->pdo_mysql->execute()");
return false;
}
if ($va_tmp['prepare']) {
$opo_statement = $this->opr_db->prepare($va_tmp['sql']);
}
if (Db::$monitor) {
$t = new Timer();
}
try {
$opo_statement->closeCursor();
$opo_statement->execute(is_array($va_tmp['values']) && sizeof($va_tmp['values']) ? array_values($va_tmp['values']) : null);
} catch (PDOException $e) {
$po_caller->postError($po_caller->nativeToDbError($this->opr_db->errorCode()), $e->getMessage() . (__CA_ENABLE_DEBUG_OUTPUT__ ? "\n<pre>" . caPrintStacktrace() . "\n{$ps_sql}</pre>" : ""), "Db->pdo_mysql->execute()");
return false;
}
if (Db::$monitor) {
Db::$monitor->logQuery($ps_sql, $pa_values, $t->getTime(4), $opo_statement->rowCount());
}
return new DbResult($this, $opo_statement);
}
示例12: up_insert_courses
/**
* Create each course in the moodle database
*
* @param type $courses
*/
function up_insert_courses($courses)
{
!empty($courses) or die('No courses to import!');
// counters for created and failed courses
$courses_created = 0;
$courses_failed = 0;
// Start timer for script
$ts_timer = new Timer();
$ts_timer->start();
$j = 0;
// Start Counter //
// cycle through each of the courses and get their information
foreach ($courses as $data) {
if (UP_DEBUG) {
print "<br /><br />ROW: {$j}<br />";
print "COURSEID : " . $data->idnumber . '<br />';
print "SHORTNAME : " . $data->shortname . '<br />';
print "FULLNAME : " . $data->fullname . '<br />';
print "STARTDATE : " . $data->startdate . '<br />';
print "ENDDATE : " . $data->enddate . '<br />';
print "TERMCODE : " . $data->termcode . '<br />';
}
$createstatus = up_insert_course($data);
switch ($createstatus) {
case COURSE_ALREADY_EXISTS:
if (UP_DEBUG) {
print "COURSE ALREADY EXISTS<br />";
}
break;
case COURSE_CREATION_FAILED:
if (UP_DEBUG) {
print "COURSE CREATION FAILED<br />";
$courses_failed++;
}
break;
case COURSE_CREATION_SUCCEEDED:
if (UP_DEBUG) {
print "COURSE CREATION SUCCEDED<br />";
$courses_created++;
}
break;
case true:
print "Testing!";
break;
}
$j++;
}
$ts_timer->finish();
// end foreach( $results as $data ) //
echo '<br />action took: ' . $ts_timer->getTime() . " seconds.<br />" . "<br /> Courses created: " . $courses_created . " | Courses failed: " . $courses_failed;
}
示例13: foreach
$class = Logger::$_classes[$module];
// loop through module logging arguments
//multiple args mean multiple charts like mysql or network modules
foreach ($moduleSettings['logging']['args'] as $args) {
$args = json_decode($args);
// decode arguments
$class->logfile = $logdir . $args->logfile;
// the modules logfile si read from args
//check for logdir
if (isset($moduleSettings['module']['hasownlogdir']) && $moduleSettings['module']['hasownlogdir'] == "true") {
$class->logdir = $args->logdir;
// the modules logdir as read from args
}
//see if we are timing, if so set start time
if ($timemode) {
$st = $timer->getTime();
}
//
//run modules logger
$responseData = $class->logData($logMode);
// if API then collect data for API server
if ($api) {
//TODO: nead a way to deal with modules that return more than one dataset for api
//this is for networking module
if (is_array($responseData)) {
$timestamp = "";
$dataInterface = "";
foreach ($responseData as $interface => $value) {
//echo 'INT: ' . $interface . ' VAL: ' . $value . "\n";
$data = explode("|", $value);
// parsing response data
示例14: execute
/**
* Executes a SQL statement
*
* @param mixed $po_caller object representation of the calling class, usually Db()
* @param DbStatement $opo_statement
* @param string $ps_sql SQL statement
* @param array $pa_values array of placeholder replacements
*/
public function execute($po_caller, $opo_statement, $ps_sql, $pa_values)
{
if (!$ps_sql) {
$opo_statement->postError(240, _t("Query is empty"), "Db->mysqli->execute()");
return false;
}
$vs_sql = $ps_sql;
$va_placeholder_map = $opo_statement->getOption('placeholder_map');
$vn_needed_values = sizeof($va_placeholder_map);
if ($vn_needed_values != sizeof($pa_values)) {
$opo_statement->postError(285, _t("Number of values passed (%1) does not equal number of values required (%2)", sizeof($pa_values), $vn_needed_values), "Db->mysqli->execute()");
return false;
}
for ($vn_i = sizeof($pa_values) - 1; $vn_i >= 0; $vn_i--) {
if (is_array($pa_values[$vn_i])) {
foreach ($pa_values[$vn_i] as $vn_x => $vs_vx) {
$pa_values[$vn_i][$vn_x] = $this->autoQuote($vs_vx);
}
$vs_sql = substr_replace($vs_sql, join(',', $pa_values[$vn_i]), $va_placeholder_map[$vn_i], 1);
} else {
$vs_sql = substr_replace($vs_sql, $this->autoQuote($pa_values[$vn_i]), $va_placeholder_map[$vn_i], 1);
}
}
$va_limit_info = $opo_statement->getLimit();
if ($va_limit_info["limit"] > 0 || $va_limit_info["offset"] > 0) {
if (!preg_match("/LIMIT[ ]+[\\d]+[,]{0,1}[\\d]*\$/i", $vs_sql)) {
// check for LIMIT clause is raw SQL
$vn_limit = $va_limit_info["limit"];
if ($vn_limit == 0) {
$vn_limit = 4000000000;
}
$vs_sql .= " LIMIT " . intval($va_limit_info["offset"]) . "," . intval($vn_limit);
}
}
if (Db::$monitor) {
$t = new Timer();
}
if (!($r_res = mysqli_query($this->opr_db, $vs_sql))) {
//print "<pre>".caPrintStacktrace()."</pre>\n";
$opo_statement->postError($this->nativeToDbError(mysqli_errno($this->opr_db)), mysqli_error($this->opr_db), "Db->mysqli->execute()");
return false;
}
if (Db::$monitor) {
Db::$monitor->logQuery($ps_sql, $pa_values, $t->getTime(4), is_bool($r_res) ? null : mysqli_num_rows($r_res));
}
return new DbResult($this, $r_res);
}
示例15: dispatchLoopShutdown
public function dispatchLoopShutdown()
{
//
// Force output to be sent - we need the client to have the page before
// we start flushing progress bar updates
//
$app = AppController::getInstance();
$req = $app->getRequest();
$resp = $app->getResponse();
$resp->sendResponse();
$resp->clearContent();
//
// Do reindexing
//
if ($req->isLoggedIn() && $req->user->canDoAction('can_do_search_reindex')) {
set_time_limit(3600 * 8);
$o_db = new Db();
$t_timer = new Timer();
$va_table_names = array('ca_objects', 'ca_object_lots', 'ca_places', 'ca_entities', 'ca_occurrences', 'ca_collections', 'ca_storage_locations', 'ca_object_representations', 'ca_representation_annotations', 'ca_lists', 'ca_list_items', 'ca_loans', 'ca_movements', 'ca_tours', 'ca_tour_stops');
$vn_tc = 0;
foreach ($va_table_names as $vs_table) {
require_once __CA_MODELS_DIR__ . "/{$vs_table}.php";
$t_table = new $vs_table();
$vs_pk = $t_table->primaryKey();
$qr_res = $o_db->query("SELECT {$vs_pk} FROM {$vs_table}");
if ($vs_label_table_name = $t_table->getLabelTableName()) {
require_once __CA_MODELS_DIR__ . "/{$vs_label_table_name}.php";
$va_table_names[] = $vs_label_table_name;
$t_label = new $vs_label_table_name();
$vs_label_pk = $t_label->primaryKey();
$qr_labels = $o_db->query("SELECT {$vs_label_pk} FROM {$vs_label_table_name}");
$vn_c = 0;
$vn_num_rows = $qr_labels->numRows();
$vn_table_num = $t_label->tableNum();
while ($qr_labels->nextRow()) {
$vn_label_pk_val = $qr_labels->get($vs_label_pk);
if (!($vn_c % 100)) {
caIncrementSortValueReloadProgress($vn_c, $vn_num_rows, null, null, $t_timer->getTime(2), memory_get_usage(true), $va_table_names, $vn_table_num, $t_label->getProperty('NAME_PLURAL'), $vn_tc + 1);
}
if ($t_label->load($vn_label_pk_val)) {
$t_label->setMode(ACCESS_WRITE);
$t_label->update();
}
$vn_c++;
}
$vn_tc++;
}
$vn_table_num = $t_table->tableNum();
$vn_num_rows = $qr_res->numRows();
$vn_c = 0;
while ($qr_res->nextRow()) {
$vn_pk_val = $qr_res->get($vs_pk);
if (!($vn_c % 100)) {
caIncrementSortValueReloadProgress($vn_c, $vn_num_rows, null, null, $t_timer->getTime(2), memory_get_usage(true), $va_table_names, $vn_table_num, $t_table->getProperty('NAME_PLURAL'), $vn_tc + 1);
}
if ($t_table->load($vn_pk_val)) {
$t_table->setMode(ACCESS_WRITE);
if ($vs_table == 'ca_object_representations') {
$t_table->set('md5', $t_table->getMediaInfo('ca_object_representations.media', 'original', 'MD5'));
$t_table->set('mimetype', $t_table->getMediaInfo('ca_object_representations.media', 'original', 'MIMETYPE'));
$va_media_info = $t_table->getMediaInfo('ca_object_representations.media');
$t_table->set('original_filename', $va_media_info['ORIGINAL_FILENAME']);
}
$t_table->update();
if ($vs_table == 'ca_object_representations') {
if (!$t_table->getPreferredLabelCount()) {
$t_table->addLabel(array('name' => trim($va_media_info['ORIGINAL_FILENAME']) ? $va_media_info['ORIGINAL_FILENAME'] : _t('Representation')), $pn_locale_id, null, true);
}
}
}
$vn_c++;
}
$vn_tc++;
}
caIncrementSortValueReloadProgress(1, 1, _t('Elapsed time: %1', caFormatInterval($t_timer->getTime(2))), _t('Index rebuild complete!'), $t_timer->getTime(2), memory_get_usage(true), $va_table_names, null, null, sizeof($va_table_names));
}
}