function process($arguments) { $dump_data = false; $term = get_term_default(); array_shift($arguments); if (!isset($arguments[0])) { $arguments[0] = '-h'; } $argCount = count($arguments); for ($i = 0; $i < $argCount; $i++) { if ($arguments[$i] == '-h') { print_help(); exit; } elseif ($arguments[$i] == '-f') { $i++; if (!isset($arguments[$i])) { exit("Configuration file not included.\n"); } $file_directory = $arguments[$i]; } elseif ($arguments[$i] == '-n') { $i++; if (!isset($arguments[$i])) { exit("Student rows not included.\n"); } $number_of_students = $arguments[$i]; } elseif ($arguments[$i] == '-x') { $dump_data = true; } elseif ($arguments[$i] == '-t') { $i++; if (!isset($arguments[$i])) { exit("Term is missing.\n"); } $term = $arguments[$i]; } else { exit("Unknown command\n"); } } if (empty($number_of_students)) { $number_of_students = NUMBER_OF_STUDENTS; } include_database_file($file_directory); if ($dump_data) { $response = readline("Are you sure you want to reset ALL your student tables? (y/N):"); if ($response == 'y') { reset_tables(); } else { echo "Ending script.\n\n"; exit; } echo "\nReset complete.\n------------------------------------\n\n"; } build_table(); echo TABLE_NAME . " table created.\n"; echo "------------------------------------\n\n"; echo "Creating {$number_of_students} students.\n\n"; insert_rows($number_of_students, $term); echo "------------------------------------\nStudent creation complete.\n\n"; echo "Make sure your inc/hms_defines.php file contains the following setting:\ndefine('SOAP_OVERRIDE_FILE', 'FakeSoapTable.php');\n"; }
function add_copied_order_to_rt($row_id, $control_num) { global $db; global $client_id; global $user_id; function insert_rows($rows) { global $db; global $client_id; global $user_id; foreach ($rows as $row) { $order_num = define_next_order_num_for_rt(); $query = "INSERT INTO `" . CALCULATE_TBL . "` SET "; if ($row['type'] == 'order') { $params[] = "`order_num` = '" . $order_num . "',`date` = CURRENT_TIMESTAMP() "; } foreach ($row as $key => $val) { if ($key != 'id' && $key != 'time_change' && $key != 'order_num' && $key != 'date' && $key != 'marker_kp' && $val != '') { $params[] = "`" . $key . "` = '" . $val . "' "; } } $query .= implode(',', $params); //echo $query; //echo '<br>'; //exit; $result = mysql_query($query, $db); if (!$result) { exit(mysql_error()); } else { make_note_to_rt_protocol('insert', $row['type'], mysql_insert_id($db), $user_id, $client_id); } if (isset($params)) { unset($params); } } } // схема: // 1). блокируем таблицу CALCULATE_TBL // 2). производим изменения в таблице CALCULATE_TBL // 3). разболкируем таблицы CALCULATE_TBL // 1) mysql_query("LOCK TABLES " . CALCULATE_TBL . " WRITE, " . CALCULATE_TBL_PROTOCOL . " WRITE ") or die(mysql_error()); $row_id = check_changes_to_rt_protocol($control_num, $row_id); if ($row_id == false) { mysql_query("UNLOCK TABLES") or die(mysql_error()); return; } // 2) $query = "SELECT*FROM `" . CALCULATE_TBL . "` WHERE `id` <= '" . $row_id . "' AND `client_id` = '" . $client_id . "' ORDER BY id DESC "; $result = mysql_query($query, $db) or die(mysql_error()); if (mysql_num_rows($result) > 0) { while ($item = mysql_fetch_assoc($result)) { if ($item['type'] == 'order' && $item['id'] != $row_id) { break; } $rows[] = $item; } insert_rows(array_reverse($rows)); //exit; } mysql_query("UNLOCK TABLES") or die(mysql_error()); header('Location:?' . addOrReplaceGetOnURL('', 'add_copied_order_to_rt&order_row_id&control_num')); exit; }
function append_rows($service, $tableID, $taxon) { $rows = prepare_data($taxon['concept_id']); //append batches of 10k $i = 0; $partial = array(); //initialize foreach ($rows as $row) { if (number_of_cols($row) != 11) { continue; } //exclude row if total no. of cols is not 11, if not it will cause Fatal error "(400) Content has a different number of columns than the table". $row = str_replace('"', "'", $row); //need to do this to avoid "Parsing failure. Quotation mark found in unquoted value" $partial[] = $row; $i++; if ($i % 10000 == 0) { echo "\n[{$i}]\n"; insert_rows($partial, $tableID, $service); echo "...sleep 20 secs...\n"; sleep(20); $i = 0; $partial = array(); //initialize again... } } if ($partial) { insert_rows($partial, $tableID, $service); } //insert last batch }