getMessage(); } /** * remoteMongoConnect() -- file method * * This method will attempt to make a connection to a remote mongo service, and ping the admin db, to validate the * resource's connection parameters. * * There are four input parameters to the method: * * $mongoDSN - string value containing the mongo Data Source Name * $remoteMongoAuthSource - string value containing the db name the user will authenticate against * $migErrors - call-by-reference array parameter, container for error messages * $mongoOptions - optional array parameter for mongo resource-connection options * * The method will connect to the resource, authenticating against the named collection, and ping the admin service * to verify that the remote connection is valid an accepting connection requests. * * The method returns a boolean value to indicate success or failure. * * * @author mike@givingassistant.org * @version 1.0 * * @param string $mongoDSN * @param string $remoteMongoAuthSource * @param array $migErrors * @param array|null $mongoOptions * @return bool * * * HISTORY: * ======== * 10-01-18 mks DB-43: original coding * */ function remoteMongoConnect(string $mongoDSN, string $remoteMongoAuthSource, array &$migErrors, array $mongoOptions = null): bool { $remoteMongoConnection = false; // now that we have the DSN built, test the connection by connecting and pinging the authDB service try { if (isset($mongoOptions) and is_array($mongoOptions)) $manager = new MongoDB\Driver\Manager($mongoDSN, $mongoOptions); else $manager = new MongoDB\Driver\Manager($mongoDSN); $command = new MongoDB\Driver\Command(['ping' => 1]); $results = $manager->executeCommand($remoteMongoAuthSource, $command); $results = $results->toArray(); $remoteMongoConnection = ($results[0]->ok == 1); } catch (MongoDB\Driver\Exception\ConnectionException | MongoDB\Driver\Exception\InvalidArgumentException | MongoDB\Driver\Exception\RuntimeException | MongoDB\Driver\Exception\Exception $e) { $migErrors[] = ERROR_MONGO_CONNECT; $migErrors[] = $e->getMessage(); } return $remoteMongoConnection; } /** * remoteMysqlConnect() - file method * * This method attempts to make a connection to a remote mysql resource and, if the connection is successful, then * submits a simple query to validate that resource. * * There are seven input parameters passed to this method: * * $PDOConnectString - string value that has the PDO connect string... self-documenting, yo * $user - string value containing the authenticating user's account name * $pass - string value containing the authenticating user's password * $tableName - string value containing the table we'll pull from/test * $pdoAttributes - array value containing PDO specific attributes passed to the resource constructor * $migErrors - array, call-by-reference value, that will implicitly return any error messages to the calling client * $rowCount - integer, call-by-reference value, that will implicitly return the row count of the named table * * The method returns a boolean value indicating if the remote connection was successful *and* if we were able a * row count from the targeted table. * * * @author mike@givingassistant.org * @version 1.0 * * @param string $PDOConnectString * @param string $user * @param string $pass * @param string $tableName * @param array $pdoAttributes * @param array $migErrors * @param int $rowCount * @return bool * * * HISTORY: * ======== * 10-01-18 mks DB-43: original coding * */ function remoteMysqlConnect(string $PDOConnectString, string $user, string $pass, string $tableName, array $pdoAttributes, array &$migErrors, int &$rowCount): bool { $resRemote = null; $queryResults = null; try { $resRemote = new PDO($PDOConnectString, $user, $pass, $pdoAttributes); $query = 'SELECT COUNT(1) AS numRecs FROM ' . $tableName; foreach ($resRemote->query($query) as $results) $queryResults = $results; if (is_array($queryResults) and isset($queryResults[STRING_NUM_RECS])) $rowCount = $queryResults[STRING_NUM_RECS]; return true; } catch (PDOException | Throwable $e) { $msg = basename(__FILE__) . COLON_NS . __LINE__ . COLON . ERROR_PDO_CONNECT; $migErrors[] = $msg; $migErrors[] = $e->getMessage(); } return false; } /** * validateMigrationDate() -- file method * * This method validates a date string, passed as the first input parameter, retrieved from the datePicker widget. The * second input parameter is an optional date-format string. * * The method returns a boolean indicating if the date is valid. If you change the date format in date-picker, then * you'll need to update how this method is called by using the optional second parameter. * * * @author mike@givingassistant.org * @version 1.0 * * @param string $date - string containing the date string returned by the date-picker widget * @param string $dateFormat - format of the date string returned by the date-picker widget * @return bool * * * HISTORY: * ======== * 10-02-18 mks DB-43: original coding * */ function validateMigrationDate(string $date, $dateFormat = 'j F, Y'): bool { $d = DateTime::createFromFormat($dateFormat, $date); return $d && $d->format($dateFormat) === $date; } // lvar initialization $rc = 0; $savedData = []; $templateName = STRING_UNKNOWN; $cfgRemote = []; $cfgNamaste = null; $cfgMig = null; $disableNamasteSchema = false; $haveTemplateNameError = false; $g2g = false; // squelch IDE warnings $defaultRemoteMysql = $defaultRemoteMongo = $defaultNamasteMongo = $defaultNamasteMysql = null; $remoteMongoAuthSource = $remoteMongoURI = $remoteMongoPort = $remoteMongoCollection = $remoteMongoPassword = null; $remoteMysqlURI = $remoteMysqlPort = $remoteMysqlLogin = $remoteMysqlPassword = null; $remoteMysqlTableName = $remoteMysqlStartDate = $remoteMysqlEndDate = null; $importDeletes = $importPartials = $testMode = $validateRemoteSource = 0; $submitLTO = 0; $startMigration = 0; $beginMigration = 0; $remoteMongoDatabase = $remoteMysqlDBName = ''; $haveValidTemplate = false; $haveValidSource = false; $haveValidDestination = false; $haveLogin = false; $havePassword = false; $haveAuthDB = false; $haveValidSource = false; $haveValidDestination = false; $migErrors = []; $mongoOptions = []; $remoteSchema = ''; $namasteSchema = ''; $patternUriPort = '/(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])(:[0-9]+)?$/'; // load the migration defaults from the Namaste XML structure if (!empty(gasConfig::$settings[CONFIG_MIGRATION])) { $cfgMig = gasConfig::$settings[CONFIG_MIGRATION]; } else { // fatal error -- rudely die exit (CONFIG_XML_LOAD); } // production check: are Login and Password required? $lpRequired = (gasConfig::$settings[CONFIG_ID][CONFIG_ID_ENV] == ENV_PRODUCTION); // load list of valid template names try { $templateNames = gasStatic::loadValidTemplateNames(); } catch (TypeError $t) { exit ($t->getMessage()); } /* * This is a critical section - when the form self-posts, it saves all variables into a single associative array * that's keyed by the variable name. This variable is stored as a base64-encoded json string as a hidden field. * * New variables will override the variables in this array but, once processing is complete, this array becomes * the "authority" for all form-control variables in the HTML. * */ if (!empty($_POST)) { // first - pull and remove the savedData from the $_POST if available if (!empty($_POST['savedData'])) { // radio buttons are handled separately $rbs = ['defaultNamasteMongo', 'defaultNamasteMysql', 'defaultRemoteMongo', 'defaultRemoteMysql']; $savedData = json_decode(base64_decode(htmlspecialchars(stripslashes($_POST['savedData']))), true); unset($_POST['savedData']); } // next, loop through the rest of the $_POST and extract into identically-named PHP vars foreach ($_POST as $key => $value) { if (in_array($key, $rbs)) { // if the post var is a radio-button $$key = boolval($value); // convert to a boolean value $savedData[$key] = boolval($value); } else { $savedData[$key] = htmlspecialchars(strip_tags($value)); // stash in saved-var container $$key = htmlspecialchars(strip_tags($value)); // otherwise, everything else is a string } } } /* * once the form variables, and the POST vars, are loaded and saved, we need to determine which event triggered * the post and take the action appropriate to the event... */ // logically, the first event that should be fired on a new page load is the template selection modal... // The template has to be validated (contains a migration section) and the information in the valid template // subsequently also populates the destination (Namaste) configuration... // Also, do NOT process the template name if we clicked the validate-remote-source button... if (isset($_POST['templateName']) and $validateRemoteSource != 1) { $templateName = htmlspecialchars(stripslashes($_POST['templateName'])); $tName = STRING_CLASS_GAT . htmlspecialchars(stripslashes($_POST['templateName'])) . STRING_CLASS_FILE_EXT; $tObjName = STRING_CLASS_GAT . htmlspecialchars(stripslashes($_POST['templateName'])); $tFile = $templateDir . SLASH . $tName; // validate that the template file exists if (!file_exists($tFile)) { $errorList[] = ERROR_TEMPLATE_FILE_404 . $templateName; $templateName = $errorList; $haveTemplateNameError = true; } else { // we have a template file - set the Namaste (destination) and source schema data based on the selected-template try { /** @var gatProdRegistrations $tObj */ $tObj = new $tObjName(); // ensure that the template has a valid migration section if (!isset($tObj->migrationMap) or !is_array($tObj->migrationMap)) { $errorList[] = ERROR_MIGRATION_MAP_404; $templateName = STRING_UNKNOWN; } else { $savedData['templateName'] = $templateName; $pdoConfig = gasConfig::$settings[CONFIG_DATABASE][CONFIG_DATABASE_PDO][CONFIG_DATABASE_PDO_APPSERVER][CONFIG_DATABASE_PDO_MASTER]; $mdbConfig = gasConfig::$settings[CONFIG_DATABASE][CONFIG_DATABASE_MONGODB][CONFIG_DATABASE_MONGODB_APPSERVER]; // load the destination configuration switch ($tObj->schema) { case TEMPLATE_DB_PDO : $defaultNamasteMysql = true; $savedData[NAMASTE_HOST] = $pdoConfig[CONFIG_DATABASE_PDO_HOSTNAME]; $savedData[NAMASTE_PORT] = $pdoConfig[CONFIG_DATABASE_PDO_PORT]; $savedData[NAMASTE_SCHEMA] = STRING_MYSQL; $savedData[NAMASTE_USER] = $pdoConfig[CONFIG_DATABASE_PDO_USERNAME]; $savedData[NAMASTE_PASS] = $pdoConfig[CONFIG_DATABASE_PDO_PASSWORD]; $savedData[NAMASTE_DB] = gasConfig::$settings[CONFIG_ID][CONFIG_ID_ENV] . $pdoConfig[CONFIG_DATABASE_PDO_DB]; $savedData[NAMASTE_TABLE] = $tObj->collection; $savedData[NAMASTE_CHARSET] = $pdoConfig[CONFIG_DATABASE_PDO_CHARSET]; break; case TEMPLATE_DB_MONGO : $defaultNamasteMongo = true; $savedData[NAMASTE_HOST] = $mdbConfig[CONFIG_DATABASE_MONGODB_HOST]; $savedData[NAMASTE_PORT] = $mdbConfig[CONFIG_DATABASE_MONGODB_PORT]; $savedData[NAMASTE_SCHEMA] = STRING_MONGO; $savedData[NAMASTE_USER] = $mdbConfig[CONFIG_DATABASE_MONGODB_USER]; $savedData[NAMASTE_PASS] = $mdbConfig[CONFIG_DATABASE_MONGODB_PASSWORD]; $savedData[NAMASTE_DB] = gasConfig::$settings[CONFIG_ID][CONFIG_ID_ENV] . UDASH . $mdbConfig[CONFIG_DATABASE_MONGODB_DB_NAME]; $savedData[NAMASTE_TABLE] = $tObj->collection; $savedData[NAMASTE_AUTH_SOURCE] = $mdbConfig[CONFIG_DATABASE_MONGODB_AUTH_SOURCE]; if ($mdbConfig[NAMASTE_INSTANCE_TYPE] == CONFIG_INSTANCE_TYPE_SHARD) { $savedData[NAMASTE_SHARD_SERVER] = $mdbConfig[CONFIG_DATABASE_MONGODB_SHARDING_MONGOS_NODES]; } elseif ($mdbConfig[NAMASTE_INSTANCE_TYPE] == CONFIG_INSTANCE_TYPE_REPL) { $savedData[NAMASTE_REPL_SET_NAME] = $mdbConfig[CONFIG_DATABASE_MONGODB_REPLSET_NAME]; foreach ($mdbConfig[CONFIG_DATABASE_MONGODB_ADMIN_REPLSET_SET] as $node) $savedData[MONGO_REPL_SET_LIST][] = $node; } break; case TEMPLATE_DB_DDB : $errorList[] = sprintf(ERROR_SCHEMA_NOT_SUPPORTED, TEMPLATE_DB_DDB); break; default : $errorList[] = sprintf(ERROR_MIGRATION_SCHEMA_UNKNOWN, $tObj->schema); break; } // load the source configuration if (!isset($tObj->migrationSourceSchema) or empty($tObj->migrationSourceSchema)) { $errorList[] = ERROR_WF_MIG_TEMPLATE_SCHEMA_404; } else { switch ($tObj->migrationSourceSchema) { case STRING_MYSQL : $defaultRemoteMysql = true; $haveValidTemplate = true; $cfgRemote = gasConfig::$settings[CONFIG_MIGRATION][CONFIG_SCHEMA_MYSQL]; $savedData[STRING_HOST] = $cfgRemote[STRING_HOST]; $savedData[STRING_PORT] = $cfgRemote[STRING_PORT]; $savedData[REMOTE_SCHEMA] = STRING_MYSQL; $savedData[STRING_USER] = $cfgRemote[STRING_USER]; $savedData[STRING_PASS] = $cfgRemote[STRING_PASS]; $savedData[CONFIG_DATABASE] = $cfgRemote[CONFIG_DATABASE]; $savedData[CONFIG_DATABASE_PDO_CHARSET] = $cfgRemote[CONFIG_DATABASE_PDO_CHARSET]; break; case STRING_MONGO : $defaultRemoteMongo = true; $haveValidTemplate = true; $cfgRemote = gasConfig::$settings[CONFIG_MIGRATION][CONFIG_SCHEMA_MONGO]; $savedData[STRING_HOST] = $cfgRemote[STRING_HOST]; $savedData[STRING_PORT] = $cfgRemote[STRING_PORT]; $savedData[REMOTE_SCHEMA] = STRING_MONGO; $savedData[STRING_USER] = $cfgRemote[STRING_USER]; $savedData[STRING_PASS] = $cfgRemote[STRING_PASS]; $savedData[STRING_AUTH_SRC] = $cfgRemote[CONFIG_DATABASE_MONGODB_AUTH_SOURCE]; $savedData[CONFIG_DATABASE] = $cfgRemote[CONFIG_DATABASE]; if ($cfgRemote[CONFIG_INSTANCE_TYPE] == CONFIG_INSTANCE_TYPE_SHARD) { $savedData[REMOTE_SHARD_SERVER] = $cfgRemote[CONFIG_DATABASE_MONGODB_SHARDING_MONGOS_NODES]; } elseif ($cfgRemote[CONFIG_INSTANCE_TYPE] == CONFIG_INSTANCE_TYPE_REPL) { $savedData[MONGO_REPL_SET] = $cfgRemote[CONFIG_DATABASE_MONGODB_REPLSET_NAME]; foreach ($cfgRemote[CONFIG_DATABASE_MONGODB_REPLSET_DSN] as $value) $savedData[MONGO_REPL_SET_LIST][] = $value; } break; default : $errorList[] = ERROR_WF_MIG_REMOTE_SCHEMA; break; } } } if (is_object($tObj)) $tObj->__destruct(); unset($tObj); } catch (Throwable $t) { $templateName = STRING_UNKNOWN; $errorList[] = $t->getMessage(); } } } // next - see if any of the default (Namaste XML) configurations have been selected and validate... if ($defaultRemoteMysql and $defaultRemoteMysql === $defaultRemoteMongo) $errorList[] = ERROR_HTML_MIG_FORM_ERROR . ' Remote RBs are the same'; if ($defaultNamasteMysql and $defaultNamasteMysql === $defaultNamasteMongo) $errorList[] = ERROR_HTML_MIG_FORM_ERROR . ' Namaste RBs are the same'; // if one of the RBs was clicked, assign the default (XML) configuration if ($defaultRemoteMysql) { $cfgRemote = $cfgMig[STRING_MYSQL]; $savedData['defaultRemoteMysql'] = $cfgRemote; if (isset($savedData['defaultRemoteMongo'])) unset($savedData['defaultRemoteMongo']); $haveValidSource = true; $remoteSchema = STRING_MYSQL; } if ($defaultRemoteMongo) { $cfgRemote = $cfgMig[STRING_MONGO]; $savedData['defaultRemoteMongo'] = $cfgRemote; if (isset($savedData['defaultRemoteMysql'])) unset($savedData['defaultRemoteMysql']); $haveValidSource = true; $remoteSchema = STRING_MONGO; } // we need to validate the remote table if ($validateRemoteSource == 1) { if (empty($remoteTableName)) $migErrors[] = ERROR_WF_MIG_TABLE_404; else $savedData['remoteTableName'] = $remoteTableName; if (!empty($remoteXMLStartDate)) { if (!validateMigrationDate($remoteXMLStartDate)) { $migErrors[] = sprintf(ERROR_WF_MIG_DATE_BAD, 'Start', $remoteXMLStartDate); } } if (!empty($remoteXMLEndDate)) { if (!validateMigrationDate($remoteXMLEndDate)) { $migErrors[] = sprintf(ERROR_WF_MIG_DATE_BAD, 'End', $remoteMysqlEndDate); } } } // if we're overriding the default Source XML, process that data... $validRemoteMongoConfig = false; // remote source is mongo schema if (isset($changeDefaultMongo) and $changeDefaultMongo == 1) { // validate that we have the minimum data -- either we need a remote URI and Port, or a replSet name and node list if ((!isset($remoteMongoURI) or empty($remoteMongoURI) and (!isset($remoteMongoPort)) or empty($remoteMongoPort)) and ((!isset($remoteMongoReplSet) or empty($remoteMongoReplSet)) and (!isset($remoteMongoReplSetList) or empty($remoteMongoReplSetList))) or (isset($remoteMongoURI) and isset($remoteMongoReplSet))) { // neither the URI, Port, ReplSetName, or ReplSetList have been set $migErrors[] = ERROR_WF_MIG_REMOTE_MONGO_404; } elseif (isset($remoteMongoURI) and !isset($remoteMongoReplSet)) { // remoteMongoURI is set -- validate if (isset($remoteMongoReplSet) and !empty($remoteMongoReplSet)) { $migErrors[] = ERROR_WF_MIG_REMOTE_MONGO_404; } elseif (empty($remoteMongoPort)) { $migErrors[] = ERROR_WF_MIG_PORT_404; } else { $cfgRemote[STRING_HOST] = $remoteMongoURI; $cfgRemote[STRING_PORT] = $remoteMongoPort; } } elseif (isset($remoteMongoPort) and !isset($remoteMongoURI)) { $migErrors[] = ERROR_WF_MIG_URI_404; } elseif (isset($remoteMongoReplSet) and !isset($remoteMongoReplSetList)) { $migErrors[] = ERROR_WF_MIG_REPL_500; } elseif (isset($remoteMongoReplSet) and isset($remoteMongoReplSetList)) { $cfgRemote[MONGO_REPL_SET_LIST] = $remoteMongoReplSetList; $savedData[MONGO_REPL_SET_LIST] = $remoteMongoReplSetList; // if we have a replication set, we need a replSet name and at least three members of the repl set, // each of which must consist of a domainName/IP-Address:PortNumber $replSetErrors = false; if (false == ($rmr = preg_split("/[\s,]+/", $remoteMongoReplSetList))) { $migErrors[] = ERROR_WF_MIG_REPL_BAD; $replSetErrors = true; } else { $remoteMongoReplSetList = null; $validPatterns = true; foreach ($rmr as $hp) { if (!empty($hp) and 1 !== preg_match($patternUriPort, $hp)) { $migErrors[] = sprintf(ERROR_WF_MIG_REPL_URL, $hp); $validPatterns = false; $replSetErrors = true; } elseif (!empty($hp)) { $remoteMongoReplSetList[] = $hp; } } if (count($rmr) < 3) { $migErrors[] = ERROR_WF_MIG_REPL_NUM; $replSetErrors = true; } } } // todo -- date validation // if production then ensure we have requisite login data if ($lpRequired) { if (!isset($remoteMongoLogin)) $migErrors[] = ERROR_WF_MIG_LOGIN_404; if (!isset($remoteMongoPassword)) $migErrors[] = ERROR_WF_MIG_PWD_404; if (!isset($remoteMongoAuthSource)) $migErrors[] = ERROR_WF_MIG_ADB_404; } // if we have a login, then we also have to have a password and an authDB (regardless if production) if (isset($remoteMongoLogin) and !empty($remoteMongoLogin)) { $cfgRemote[STRING_USER] = $remoteMongoLogin; $haveLogin = true; } if (isset($remoteMongoPassword) and !empty($remoteMongoPassword)) if (!$haveLogin) $migErrors[] = ERROR_WF_MIG_LOGIN_MISSING; else { $cfgRemote[STRING_PASS] = $remoteMongoPassword; $havePassword = true; } elseif ($haveLogin) $migErrors[] = ERROR_WF_MIG_PWD_MISSING; if (isset($remoteMongoAuthSource) and !empty($remoteMongoAuthSource)) { if (!$haveLogin) $migErrors[] = ERROR_WF_MIG_LOGIN_MISSING; if (!$havePassword) $migErrors[] = ERROR_WF_MIG_PWD_MISSING; $cfgRemote[REMOTE_AUTH_SOURCE] = $remoteMongoAuthSource; } elseif ($haveLogin or $havePassword) $migErrors[] = ERROR_WF_MIG_ADB_MISSING; if (!isset($remoteMongoDatabase) or empty($remoteMongoDatabase)) $migErrors[] = ERROR_WF_MIG_DB_404; else $cfgRemote[CONFIG_DATABASE] = $remoteMongoDatabase; if (empty($migErrors)) { // validate the remote mongo service -- begin by building the mongoDSN $mongoDSN = MONGO_DSN; if (isset($remoteMongoLogin)) { $mongoDSN .= $remoteMongoLogin . COLON_NS . $remoteMongoPassword . AT; $mongoOptions[CONFIG_DATABASE_MONGODB_AUTH_SOURCE] = $remoteMongoAuthSource; } if (isset($remoteMongoReplSet)) { // replication set $mongoOptions[MONGO_REPL_SET] = $remoteMongoReplSet; foreach ($remoteMongoReplSetList as $remoteNode) $mongoDSN .= $remoteNode . ','; $mongoDSN = rtrim($mongoDSN, ','); } else $mongoDSN .= $remoteMongoURI . COLON_NS . $remoteMongoPort; // add the database name to the mongoDSN $mongoDSN .= SLASH . $remoteMongoDatabase; // now that we have the DSN built, test the connection by connecting and pinging the authDB service try { $remoteConnection = remoteMongoConnect($mongoDSN, $remoteMongoAuthSource, $migErrors, $mongoOptions); $haveValidSource = true; $defaultCustomSchemaLabel = 'mongoDB'; $remoteSchema = STRING_MONGO; if (isset($remoteMongoReplSet)) { $cfgRemote[MONGO_REPL_SET] = $remoteMongoReplSet; $savedData['remoteMongoReplSet'] = $remoteMongoReplSet; } } catch (TypeError $t) { $migErrors[] = $t->getMessage(); $defaultCustomSchemaLabel = 'Error!'; } $defaultCustomSchema = true; $haveValidDestination = true; $defaultRemoteMongo = false; $defaultRemoteMysql = false; } else { if (empty($errorList)) $errorList = $migErrors; else $errorList = array_merge($errorList, $migErrors); } } elseif (isset($changeDefaultMysql) and $changeDefaultMysql == 1) { // MYSQL OVERRIDE // MYSQL Override (the namaste xml file) option was selected // validate, like the mongo section, that we have the minimum data needed for remote import if ((!isset($remoteMysqlURI) or empty($remoteMysqlURI)) and (!isset($remoteMysqlPort) or empty($remoteMysqlPort)) and (!isset($remoteMysqlLogin) or empty($remoteMysqlLogin)) and (!isset($remoteMysqlPassword) or empty($remoteMysqlPassword))) { $migErrors[] = ERROR_WF_MIG_REMOTE_MYSQL_404; } if (!isset($remoteMysqlDBName) or empty($remoteMysqlDBName)) $migErrors[] = ERROR_WF_MIG_DB_404; if (!isset($remoteMysqlTableName) or empty($remoteMysqlTableName)) $migErrors[] = ERROR_WF_MIG_TABLE_404; if (empty($migErrors)) { // build the PDO connect string for the remote resource $charset = 'charset=utf8mb4'; $PDOConnectString = 'mysql:host=' . $remoteMysqlURI . COLON_NS . $remoteMysqlPort . SEMI . 'dbname=' . $remoteMysqlDBName . SEMI . $charset; $pdoAttributes = [ PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]; if (!($remoteConnection = remoteMysqlConnect($PDOConnectString, $remoteMysqlLogin, $remoteMysqlPassword, $remoteMysqlTableName, $pdoAttributes, $migErrors, $rc))) { $migErrors[] = ERROR_PDO_CONNECT . COLON . $PDOConnectString; } else { $defaultCustomSchema = true; $haveValidSource = true; $haveValidDestination = true; $defaultCustomSchemaLabel = 'mySQL'; $defaultRemoteMongo = false; $defaultRemoteMysql = false; $remoteSchema = STRING_MYSQL; } $cfgRemote[STRING_HOST] = $remoteMysqlURI; $cfgRemote[STRING_PORT] = $remoteMysqlPort; $cfgRemote[STRING_USER] = $remoteMysqlLogin; $cfgRemote[STRING_PASS] = $remoteMysqlPassword; $cfgRemote[REMOTE_AUTH_SOURCE] = NA; $cfgRemote[CONFIG_DATABASE] = $remoteMysqlDBName; // $cfgRemote[REMOTE_COLLECTION_NAME] = ; // $cfgRemote[REMOTE_START_DATE] = ; // $cfgRemote[REMOTE_END_DATE] = ; $cfgRemote[REMOTE_RECORD_COUNT] = $rc; } //} elseif (isset($startMigration) and $startMigration == 1) { } elseif (isset($submitLTO) and $submitLTO == 1) { // instantiate a migration broker client if (!isset(gasConfig::$settings[CONFIG_BROKER_SERVICES][CONFIG_BROKER_APPSERVER][CONFIG_BROKER_INSTANCES][CONFIG_BROKER_M_BROKER]) or (gasConfig::$settings[CONFIG_BROKER_SERVICES][CONFIG_BROKER_APPSERVER][CONFIG_BROKER_INSTANCES][CONFIG_BROKER_M_BROKER] < 1)) { $migErrors[] = ERROR_WF_MIG_BRK_CFG_404; } elseif (!isset($remoteSchema)) { $migErrors[] = ERROR_WF_MIG_REMOTE_SCHEMA; } else { $stopProcessing = false; // todo -- how are the XML defaults handled at this stage?!? switch ($savedData['remoteSchema']) { case STRING_MONGO : $data[MIGRATION_SOURCE_SCHEMA] = CONFIG_SCHEMA_MONGO; $data[STRING_HOST] = $remoteMongoURI; $data[STRING_PORT] = $remoteMongoPort; if (!empty($remoteMongoLogin)) $data[STRING_USER] = $remoteMongoLogin; if (!empty($remoteMongoPassword)) $data[STRING_PASS] = $remoteMongoPassword; if (!empty($remoteMongoAuthSource)) $data[STRING_AUTH_SRC] = $remoteMongoAuthSource; if (!empty($remoteMongoReplSet)) $data[CONFIG_DATABASE_MONGODB_REPLSET] = $remoteMongoReplSet; if (!empty($remoteMongoReplSetList)) $data[CONFIG_DATABASE_MONGODB_REPLSET_DSN] = $remoteMongoReplSetList; $data[CONFIG_DATABASE] = $remoteMongoDatabase; $data[MIGRATION_SOURCE_TABLE] = $remoteMongoCollection; break; case STRING_MYSQL : $data[MIGRATION_SOURCE_SCHEMA] = CONFIG_SCHEMA_MYSQL; $data[STRING_HOST] = $remoteMysqlURI; $data[STRING_PORT] = $remoteMysqlPort; if (!empty($remoteMysqlLogin)) $data[STRING_USER] = $remoteMysqlLogin; if (!empty($remoteMysqlPassword)) $data[STRING_PASS] = $remoteMysqlPassword; $data[CONFIG_DATABASE] = $remoteMysqlDBName; // $data[MIGRATION_SOURCE_TABLE] = ; break; default : $migErrors[] = sprintf(ERROR_MIGRATION_SCHEMA_UNKNOWN, $savedData['remoteSchema']); $data = null; $stopProcessing = true; break; } if (!$stopProcessing) { // testing the XML conversion here... make sure this is commented-out for production runs $newXML = gasStatic::convertWebMigrationRequest($data); // set broker payload containers $data[MIGRATION_DEST_SCHEMA] = $savedData['namasteSchema']; $data[MIGRATION_DEST_TABLE] = $savedData['templateName']; // set the schema-independent migration switches $data[MIGRATION_FILTER_SOFT_DELETES] = boolval($importDeletes); $data[MIGRATION_FILTER_PARTIALS] = boolval($importPartials); $data[MIGRATION_TEST_MODE] = boolval($testMode); // set the meta data payload $meta[META_CLIENT] = CLIENT_SYSTEM; $meta[META_SYSTEM_NOTES] = basename(__FILE__); $meta[META_CLIENT_IP] = $_SERVER['REMOTE_ADDR']; $meta[BROKER_XML_DATA] = $newXML; $haveValidSource = true; $beginMigration = 1; // submit the broker-client request to initiate the migration } } } if (isset($remoteSchema) and !empty($remoteSchema)) $savedData['remoteSchema'] = $remoteSchema; if (isset($namasteSchema) and !empty($namasteSchema)) $savedData['namasteSchema'] = $namasteSchema; $savedDataCompressed = base64_encode(json_encode($savedData)); // test to see if we can enable the copy button, authorizing the migration $g2g = ($haveValidTemplate == $haveValidSource and $haveValidSource == $haveValidDestination and $haveValidDestination == $remoteConnection and $remoteConnection == true and !$beginMigration); if (!empty($migErrors)) $errorList = array_merge($errorList, $migErrors); ?> Namaste Data Migration Manager

namasteLogo Data Migration Manager

Remote Data Source
Template: 
Host:      Port: 
Schema:  ' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; // todo - make this a source label, indicating if this is SOURCE_USER or SOURCE_NAMASTE instead... if (isset($defaultCustomSchemaLabel) and $defaultCustomSchema) { echo '' . PHP_EOL; echo '' . PHP_EOL; } ?>
Login:      Password:      Auth Database: 
Remote Database:  >
Remote Table:  Start Date:  > End Date:  >
' . PHP_EOL; echo 'Repl Set: ' . PHP_EOL; echo $savedData[MONGO_REPL_SET] . PHP_EOL; echo '' . PHP_EOL; echo '
' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; echo '
' . PHP_EOL; } if (isset($savedData[REMOTE_SHARD_SERVER])) { echo '
' . PHP_EOL; echo 'MongoS URI:Port: ' . PHP_EOL; echo $savedData[REMOTE_SHARD_SERVER] . PHP_EOL; echo '
' . PHP_EOL; } if (isset($rc) and $rc) { ?>
Num Recs: 
' . PHP_EOL; echo '' . PHP_EOL; } else { echo '' . PHP_EOL; ?>
Namaste Destination
Host:      Port: 
Database:  Table: 
Schema:  ' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; ?>
Num Recs: 

   To start a migration, first start typing the name of the desired (required) Namaste destination template. Next, select the source and destination schema, before clicking the copy button. Num Recs on the source side indicate the number of active records in the remote repository. Num Recs on the destination side will indicate the total number of records successfully migrated once the operation has completed.
Override Default Remote Migration Options
>
>
>
>
>
>
>
>
>
>
>
>