Archive: Namaste PHP AMQP framework v1.0 (2017-2020)
952 days continuous production uptime, 40k+ tp/s single node. Original corpo Bitbucket history not included — clean archive commit.
This commit is contained in:
21
stubs/arrayDiff.php
Normal file
21
stubs/arrayDiff.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
$array1 = [ 'color' => 'red', 'size' => 'XL', 'style' => 'gothic', 'brand' => 'levi', 'token' => 1 ];
|
||||
|
||||
|
||||
$array2 = [ 'color' => 1, 'brand' => 1 ];
|
||||
|
||||
$array3 = array_diff_key($array1, $array2);
|
||||
|
||||
$array4 = ['token' => mt_rand(0, 10), 'color' => 'red', 'size' => 'xl'];
|
||||
|
||||
$array5 = [ 'token' => 1 ];
|
||||
echo PHP_EOL;
|
||||
if (empty($array3))
|
||||
echo "no results returned";
|
||||
else
|
||||
var_export($array3);
|
||||
echo PHP_EOL;
|
||||
|
||||
$array4 = array_intersect_key($array1, $array5);
|
||||
var_export($array4);
|
||||
60
stubs/aryInit.php
Normal file
60
stubs/aryInit.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/*
|
||||
* aryInit.php -- test stub
|
||||
*
|
||||
* The point of this test stub is to test the initialization of member arrays. Since declared arrays cannot be set
|
||||
* to null without generating a warning, this stub tests initializing an array using the empty bracket shorthand and
|
||||
* then calls a method to add a line of text to the array.
|
||||
*
|
||||
* What we want to see, and we do, is that the initialization of the array doesn't create a blank/null first record
|
||||
* and that the newly assigned string is set to element 0 of the array.
|
||||
*
|
||||
* OUTPUT:
|
||||
* =======
|
||||
* On init:
|
||||
* testArray::__set_state(array(
|
||||
* 'foo' =>
|
||||
* array (
|
||||
* ),
|
||||
* ))
|
||||
* On insert:
|
||||
* testArray::__set_state(array(
|
||||
* 'foo' =>
|
||||
* array (
|
||||
* 0 => 'This is a test',
|
||||
* ),
|
||||
* ))
|
||||
* Execution ends.
|
||||
*
|
||||
*
|
||||
* 01-08-20 mks DB-150: original coding
|
||||
*
|
||||
*/
|
||||
class testArray {
|
||||
public array $foo;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->foo = [];
|
||||
}
|
||||
|
||||
public function addString(string $newLine): bool
|
||||
{
|
||||
if (!is_string($newLine)) return false;
|
||||
$this->foo[] = $newLine;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$objTest = new testArray();
|
||||
echo 'On init: ' . PHP_EOL;
|
||||
var_export($objTest);
|
||||
echo PHP_EOL;
|
||||
if ($objTest->addString('This is a test')) {
|
||||
echo 'On insert: ' . PHP_EOL;
|
||||
var_export($objTest);
|
||||
echo PHP_EOL;
|
||||
} else {
|
||||
echo 'Failed to insert string!' . PHP_EOL;
|
||||
}
|
||||
echo 'Execution ends.' . PHP_EOL;
|
||||
9
stubs/aryMerge.php
Normal file
9
stubs/aryMerge.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
$foo = [ 'apple', 'banana', 'cherry' ];
|
||||
|
||||
$bar = [ 'orange', 'lemon' ];
|
||||
|
||||
$bar = [...$bar, ...$foo];
|
||||
|
||||
var_export($bar);
|
||||
13
stubs/functionCheck.php
Normal file
13
stubs/functionCheck.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
// check to see if a function exists within the scope of the framework libraries
|
||||
|
||||
echo 'function array_key_exists does ' . ((function_exists('array_key_first')) ? '' : 'not ') . 'exist' . PHP_EOL;
|
||||
|
||||
// load the framework
|
||||
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
echo 'function array_key_exists does ' . ((function_exists('array_key_first')) ? '' : 'not ') . 'exist' . PHP_EOL;
|
||||
|
||||
|
||||
array_key_first([]);
|
||||
107
stubs/initTest.php
Normal file
107
stubs/initTest.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* This initTest.php script tests the "lite-loading" of the framework config. This is basically a pared-down version
|
||||
* of the bootstrap loader missing a few initialization processes. Notably missing are the singleton instantiations
|
||||
* of the static classes which, because of resM logging, add a few seconds to clients *connecting* to the framework.
|
||||
*
|
||||
* In other words, the bootstrap loader is heavy-duty and used to start the entire Namaste framework. This script
|
||||
* helped to derive a lighter version of the bootstrap loader that removes the instantiation lag.
|
||||
*
|
||||
*
|
||||
* @author mike@givingassistant.org
|
||||
* @version 1.0.0
|
||||
*
|
||||
*
|
||||
* HISTORY:
|
||||
* ========
|
||||
* 0=8-29-18 mks DB-50: original coding
|
||||
*
|
||||
*
|
||||
*/
|
||||
$eos = (isset($_SERVER['HTTP_USER_AGENT'])) ? '<br />' : PHP_EOL;
|
||||
$topDir = dirname( __DIR__ );
|
||||
|
||||
function gt(): string
|
||||
{
|
||||
return('[' . date("d/m/y@H:i:s", time()) . '] [ !]TEST: ');
|
||||
}
|
||||
|
||||
// load the files stored in the common directory
|
||||
foreach(glob($topDir . '/common/*.php') as $filename) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require_once($filename);
|
||||
}
|
||||
|
||||
$classesDir = $topDir . DIR_CLASSES;
|
||||
$configDir = $topDir . DIR_CONFIG;
|
||||
$amqpLib = $topDir . DIR_LIB;
|
||||
$templateDir = $topDir . DIR_CLASSES . DIR_TEMPLATE;
|
||||
|
||||
// load the auto-loaders (composer and namaste)
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require($topDir . FILE_AUTOLOADER);
|
||||
if(file_exists($classesDir)) {
|
||||
Autoloader::register_directory($classesDir);
|
||||
Autoloader::register_directory($templateDir);
|
||||
}
|
||||
require_once $amqpLib . '/vendor/autoload.php';
|
||||
|
||||
use /** @noinspection PhpUnusedAliasInspection */ PhpAmqpLib\Connection\AMQPStreamConnection;
|
||||
use /** @noinspection PhpUnusedAliasInspection */ PhpAmqpLib\Channel\AMQPChannel;
|
||||
use /** @noinspection PhpUnusedAliasInspection */ PhpAmqpLib\Message\AMQPMessage;
|
||||
|
||||
// load the base configuration
|
||||
if (!gasConfig::singleton($configDir . FILE_BASE_CONFIG, FILE_TYPE_XML))
|
||||
exit(gt() . 'Failed to load config singleton...' . $eos);
|
||||
if (file_exists($configDir . FILE_ENV_CONFIG)) {
|
||||
gasConfig::addConfig($configDir . FILE_ENV_CONFIG, FILE_TYPE_XML);
|
||||
if (!gasConfig::$status)
|
||||
exit(gt() . 'Failed to load/layer env configuration...' . $eos);
|
||||
}
|
||||
|
||||
|
||||
// Everything that appears above would be the new "light" loader for
|
||||
|
||||
|
||||
// test to see if we can get a mongo-master resource w/out explicitly re-declaring the singleton for the resource manager
|
||||
$mongoResource = gasResourceManager::fetchResource(RESOURCE_MONGO_MASTER, ENV_APPSERVER);
|
||||
if (!is_object($mongoResource))
|
||||
exit(gt() . ERROR_MONGO_CONNECT . COLON . RESOURCE_MONGO_MASTER . $eos);
|
||||
|
||||
// test to see if we can get a PDO master resource w/out explicitly re-declaring the resource manager singleton
|
||||
$mysqlResource = gasResourceManager::fetchResource(RESOURCE_PDO_MASTER, ENV_APPSERVER);
|
||||
if (!is_object($mysqlResource))
|
||||
exit (gt() . ERROR_PDO_CONNECT . $eos);
|
||||
|
||||
// test to see if we can get a warehouse PDO resource w/out explicitly re-declaring the resource manager singleton
|
||||
// (note: mongo warehouse resource not yet defined...)
|
||||
$whCoolRes = gasResourceManager::fetchResource(RESOURCE_WH_COOL_PDO_MASTER, ENV_SEGUNDO);
|
||||
if (!is_object($whCoolRes))
|
||||
exit(gt() . ERROR_MONGO_CONNECT . COLON . RESOURCE_WH_COOL_PDO_MASTER . $eos);
|
||||
|
||||
// test to see if we can get a PDO slave resource w/out explicitly re-declaring the resource manager singleton
|
||||
$PDOSlaveRes = gasResourceManager::fetchResource(RESOURCE_PDO_SECONDARY, ENV_APPSERVER);
|
||||
if (!is_object($PDOSlaveRes))
|
||||
exit(gt() . ERROR_PDO_CONNECT . COLON . RESOURCE_PDO_SECONDARY . $eos);
|
||||
|
||||
// test to see if we can get a broker resource w/out explicitly re-declaring the resource manager singleton
|
||||
$broker = gasResourceManager::fetchResource(RESOURCE_BROKER, ENV_APPSERVER);
|
||||
if (!is_object($broker))
|
||||
exit(gt() . ERROR_BROKER_RESOURCE . $eos);
|
||||
|
||||
// test to see if we can get an admin broker resource w/out explicitly re-declaring the resource manager singleton
|
||||
$broker = gasResourceManager::fetchResource(RESOURCE_ADMIN, ENV_APPSERVER);
|
||||
if (!is_object($broker))
|
||||
exit(gt() . ERROR_BROKER_RESOURCE . $eos);
|
||||
|
||||
// test to see if we can get a cache resource w/out explicitly re-declaring the resource manager singleton
|
||||
$resCache = gasResourceManager::fetchResource(RESOURCE_CACHE, ENV_APPSERVER);
|
||||
if (!is_object($resCache))
|
||||
exit(gt() . ERROR_BROKER_RESOURCE . $eos);
|
||||
|
||||
// test to see if we can get a tercero mongo resource w/out explicitly re-declaring the resource manager singleton
|
||||
$resTercero = gasResourceManager::fetchResource(RESOURCE_MONGO_MASTER, ENV_TERCERO);
|
||||
if (!is_object($resTercero))
|
||||
exit(gt() . ERROR_MONGO_CONNECT . COLON . RESOURCE_TERCERO . $eos);
|
||||
|
||||
exit(gt() . 'Lite resource testing successfully completed!' . $eos);
|
||||
15
stubs/qary.php
Normal file
15
stubs/qary.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
$x = [ 'id_ext' => [ 'NULLOP' => [ 'EQ' => [ '1234' ] ] ] ];
|
||||
var_dump($x);
|
||||
foreach ($x as $k1 => $v1) {
|
||||
$attr = $k1;
|
||||
foreach ($v1 as $k2 => $v2) {
|
||||
foreach ($v2 as $k3 => $v3) {
|
||||
// k3 should be op-eq
|
||||
echo 'count(v3) = ' . count($v3) . PHP_EOL;
|
||||
$value = $v3[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "Attribute: $attr, Value: $value" . PHP_EOL;
|
||||
2
stubs/snitch.php
Normal file
2
stubs/snitch.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
phpinfo();
|
||||
57
stubs/testCONS.php
Normal file
57
stubs/testCONS.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
// load the namaste environment
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
$errors = [];
|
||||
/** @var gacMongoDB $widget */
|
||||
$widget = null;
|
||||
$lastUpdated = '';
|
||||
$recordCount = 0;
|
||||
|
||||
# build meta data payload
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_CSL,
|
||||
META_CLIENT => CLIENT_SYSTEM,
|
||||
META_EVENT_GUID => guid(),
|
||||
META_LIMIT_OVERRIDE => 1, // turn off record processing limit
|
||||
META_DO_CACHE => 0
|
||||
];
|
||||
|
||||
# instantiate the template via the factory class:
|
||||
$widget = grabWidget($meta, '', $errors);
|
||||
|
||||
// read the xml file into memory to build a simulated broker payload
|
||||
$file = DIR_TMP . SLASH . 'consolidated.xml';
|
||||
if (!file_exists($file))
|
||||
exit (ERROR_FILE_404 . $file . PHP_EOL);
|
||||
elseif (false === ($contents = file_get_contents($file)))
|
||||
exit(ERROR_OPEN_XML_FILE . $file);
|
||||
$payload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_CONS,
|
||||
BROKER_DATA => [STRING_DATA => $contents],
|
||||
META_DATA => $meta
|
||||
];
|
||||
if (is_null($newFileName = $widget->template->saveCONSList($payload[BROKER_DATA], $errors)))
|
||||
exit(ERROR_SAVE_XML_FILE . DIR_TMP . PHP_EOL);
|
||||
|
||||
if (is_null($aryData = $widget->template->processCONSList($newFileName, $errors, $lastUpdated, $recordCount)))
|
||||
exit(ERROR_DATA_PROCESSING . PHP_EOL);
|
||||
|
||||
// b/c we're dealing with non-broker-submitted data, force a cache-mapping onto the data payload
|
||||
if (is_null($aryData = gasCache::buildMappedDataArray($aryData, $widget->cacheMap, $widget->ext)))
|
||||
exit(ERROR_CACHE_MAP_FAIL . $widget->class);
|
||||
|
||||
//$widget->addData($aryData);
|
||||
|
||||
$widget->_createRecord($aryData, DATA_CONS);
|
||||
if (!$widget->status) {
|
||||
var_export($widget->eventMessages);
|
||||
exit ('Processing failed' . PHP_EOL);
|
||||
} elseif ($widget->count != $recordCount) {
|
||||
exit(sprintf(ERROR_DATA_RECORD_COUNT, $recordCount, $widget->count));
|
||||
}
|
||||
|
||||
// unlink the guid-file from tmp and save the original file in the system table
|
||||
$widget->template->cleanup($newFileName);
|
||||
|
||||
echo $recordCount . ' records successfully upserted to CONS table' . PHP_EOL;
|
||||
exit('Processing successful' . PHP_EOL);
|
||||
40
stubs/testCacheMap.php
Normal file
40
stubs/testCacheMap.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* testCacheMap() -- stub utility used to test cacheMap features
|
||||
*
|
||||
* @author mike@givingassistant.org
|
||||
* @version 1.0
|
||||
*
|
||||
* HISTORY:
|
||||
* ========
|
||||
* 02-14-19 mks DB-116: original coding
|
||||
*
|
||||
*/
|
||||
|
||||
// initialization
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
$template = 'gatLogs';
|
||||
|
||||
//$vector = gasCache::fetchTemplateCacheMap($template, false);
|
||||
//if (!is_null($vector)) var_export($vector);
|
||||
//else echo 'error time - check logs' . $eos;
|
||||
|
||||
// simulate a PriceLine User request to ensure we can instantiate
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_USERS,
|
||||
META_CLIENT => CLIENT_API_USER,
|
||||
CLIENT_AUTH_TOKEN => '136EA67A-B1E2-0A4B-2BD8-EE34D39DFDE1',
|
||||
META_DO_CACHE => false,
|
||||
META_EVENT_GUID => guid()
|
||||
];
|
||||
$request = [ BROKER_REQUEST => BROKER_REQUEST_FETCH ];
|
||||
$query = [ STRING_KEY => [ OPERAND_NULL => [ OPERATOR_EQ => [null] ]]];
|
||||
$request[BROKER_DATA] = [STRING_QUERY_DATA => $query];
|
||||
$request[BROKER_META_DATA] = $meta;
|
||||
$errors = [];
|
||||
if (!validateMetaData($request, $errors))
|
||||
echo 'validateMetaData() failed' . PHP_EOL;
|
||||
else
|
||||
echo 'validateMetaData() succeeded' . PHP_EOL;
|
||||
exit;
|
||||
39
stubs/testCacheMapBroker.php
Normal file
39
stubs/testCacheMapBroker.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mshallop
|
||||
* Date: 3/6/19
|
||||
* Time: 11:00 AM
|
||||
*/
|
||||
// load the namaste environment
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
// instantiate
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_TEST_MONGO,
|
||||
META_CLIENT => CLIENT_CLIENT,
|
||||
META_CLIENT_IP => STRING_SESSION_HOME,
|
||||
META_EVENT_GUID => guid(), // simulate a broker event by generating the event guid
|
||||
];
|
||||
$errors = array();
|
||||
|
||||
$query = [
|
||||
CM_TST_FIELD_TEST_INT => [ OPERAND_NULL => [ OPERATOR_EQ => [ 4 ]]],
|
||||
CM_TST_FIELD_TEST_BOOL => [ OPERAND_NULL => [ OPERATOR_EQ => [ true ]]],
|
||||
OPERAND_AND => null
|
||||
];
|
||||
|
||||
$payload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => [ STRING_QUERY_DATA => $query ],
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
|
||||
$bc = new gacBrokerClient( BROKER_QUEUE_R, basename(__FILE__) . AT . __LINE__);
|
||||
if (!$bc->status) {
|
||||
exit(ERROR_BROKER_CLIENT_DECLARE . BROKER_QUEUE_R);
|
||||
}
|
||||
|
||||
$results = json_decode(gzuncompress($bc->call(gzcompress(json_encode($payload)))));
|
||||
|
||||
var_export($results);
|
||||
33
stubs/testCacheMapIn.php
Normal file
33
stubs/testCacheMapIn.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mshallop
|
||||
* Date: 2/26/19
|
||||
* Time: 2:12 PM
|
||||
*/
|
||||
// load the namaste environment
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
// generate test data (note: we're not instantiating anything)
|
||||
$data = gatTestMongo::buildTestData(10);
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_TEST_MONGO,
|
||||
META_CLIENT => CLIENT_CLIENT,
|
||||
META_CLIENT_IP => STRING_SESSION_HOME,
|
||||
META_EVENT_GUID => guid(), // simulate a broker event by generating the event guid
|
||||
];
|
||||
|
||||
$payload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_CREATE,
|
||||
BROKER_DATA => $data,
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
$errors = [];
|
||||
|
||||
// start the test by invoking the validation function
|
||||
$res = validateMetaData($payload,$errors);
|
||||
if ($res)
|
||||
echo 'w00t';
|
||||
else
|
||||
var_export($errors);
|
||||
echo PHP_EOL;
|
||||
35
stubs/testCacheMapOut.php
Normal file
35
stubs/testCacheMapOut.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* test stub for testing the cacheMapOut method
|
||||
*
|
||||
*/
|
||||
// load the namaste environment
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
|
||||
// build a broker request to fetch 10 random records
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_TEST_MONGO,
|
||||
META_CLIENT => CLIENT_SYSTEM,
|
||||
META_CLIENT_IP => STRING_SESSION_HOME,
|
||||
META_EVENT_GUID => guid(), // simulate a broker event by generating the event guid
|
||||
// META_LIMIT => 10
|
||||
];
|
||||
|
||||
$payload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => [ STRING_QUERY_DATA => null],
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
$errors = [];
|
||||
$ret = validateMetaData($payload, $errors);
|
||||
$obj = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, '', $errors);
|
||||
/** @var gacMongoDB $widget */
|
||||
$widget = $obj->widget;
|
||||
$widget->_fetchRecords([]);
|
||||
if (!$widget->status)
|
||||
exit(ERROR_PDO_FETCH);
|
||||
if (!gasCache::mapOutboundPayload($widget, $errors))
|
||||
var_export($errors);
|
||||
else
|
||||
var_export($widget->getCK());
|
||||
25
stubs/testCacheSmash.php
Normal file
25
stubs/testCacheSmash.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* testCacheSmash.php
|
||||
*
|
||||
* Test Stub for check the cacheMash() and smashCache() methods and returns from both method
|
||||
*
|
||||
*/
|
||||
|
||||
// initialization
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
$tokens = null;
|
||||
$errors = [];
|
||||
$maxKeys = mt_rand(100, 200);
|
||||
for ($index = 0; $index < $maxKeys; $index++)
|
||||
$tokens[] = [ guid() => 'this is a test'];
|
||||
|
||||
// call multi-cache to cache
|
||||
$keyList = gasCache::cacheMash($tokens, NUMBER_CACHE_DEFAULT, $errors);
|
||||
if (is_null($keyList)) exit ('cache mash failed');
|
||||
|
||||
// call cache-smash to remove records
|
||||
if (!gasCache::smashCache($keyList, $errors)) exit('smash cache failed');
|
||||
|
||||
$x = 1;
|
||||
49
stubs/testClone.php
Normal file
49
stubs/testClone.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* test stub for testing the clone function
|
||||
*
|
||||
*/
|
||||
// load the namaste environment
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
// using the gacFactory, build a test object for cloning
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_TEST_MONGO,
|
||||
META_CLIENT => CLIENT_SYSTEM,
|
||||
META_CLIENT_IP => STRING_SESSION_HOME,
|
||||
META_EVENT_GUID => guid() // simulate a broker event by generating the event guid
|
||||
];
|
||||
$payload1 = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => [ STRING_QUERY_DATA => null],
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
$errors = [];
|
||||
$ret = validateMetaData($payload1, $errors);
|
||||
$obj = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, '', $errors);
|
||||
/** @var gacMongoDB $widget */
|
||||
$widget = $obj->widget;
|
||||
if (is_object($obj)) $obj->__destruct();
|
||||
unset($obj);
|
||||
|
||||
// clone the widget
|
||||
$clone = clone $widget;
|
||||
|
||||
// make a query with the original object
|
||||
$widget->_fetchRecords($payload1[BROKER_DATA]);
|
||||
if (!$widget->count) exit('query failed on object 1');
|
||||
|
||||
$payload2 = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => [ STRING_QUERY_DATA =>
|
||||
[ CM_TST_FIELD_TEST_STATUS => [ OPERAND_NULL => [ OPERATOR_EQ => [ STATUS_DELETED ]]]]],
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
$clone->_fetchRecords($payload2[BROKER_DATA]);
|
||||
if (!$clone->count) exit('query failed on object 2');
|
||||
|
||||
if ($clone->count != $widget->count)
|
||||
echo 'count is different - success!';
|
||||
else
|
||||
echo 'count is the same - fail';
|
||||
|
||||
15
stubs/testConsoleLog.php
Normal file
15
stubs/testConsoleLog.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mshallop
|
||||
* Date: 7/3/18
|
||||
* Time: 7:30 AM
|
||||
*/
|
||||
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
|
||||
consoleLog('TEST: ', CON_DEBUG, INFO_TEST_MESSAGE);
|
||||
consoleLog('TEST: ', CON_SUCCESS, INFO_TEST_MESSAGE);
|
||||
consoleLog('TEST: ', CON_ERROR, INFO_TEST_MESSAGE);
|
||||
consoleLog('TEST: ', CON_SYSTEM, INFO_TEST_MESSAGE);
|
||||
13
stubs/testContinue.php
Normal file
13
stubs/testContinue.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
$x = 0;
|
||||
while ($x < 5) {
|
||||
switch ($x) {
|
||||
case 1 :
|
||||
break 2;
|
||||
// continue 2; <--- does not work
|
||||
break;
|
||||
}
|
||||
$x++;
|
||||
echo 'I am in loop 1' . PHP_EOL;
|
||||
}
|
||||
echo 'program ends with x = ' . $x . PHP_EOL;
|
||||
30
stubs/testDataFetch.php
Normal file
30
stubs/testDataFetch.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mshallop
|
||||
* Date: 6/21/17
|
||||
* Time: 10:25 AM
|
||||
*/
|
||||
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
|
||||
$guid = "F7AFFB67-20DC-DE05-F612-B1EE098D23EF";
|
||||
$meta = [
|
||||
META_CLIENT => CLIENT_SYSTEM,
|
||||
META_TEMPLATE => TEMPLATE_CLASS_LOGS,
|
||||
META_SYSTEM_NOTES => __FILE__
|
||||
];
|
||||
$errors = [];
|
||||
/** @var gacDdb $obj */
|
||||
$obj = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, $guid, $errors);
|
||||
|
||||
|
||||
echo 'Dump of User Object (clean, no-meta):' . $eos;
|
||||
var_dump($obj->widget->getData(true, false));
|
||||
|
||||
echo 'Dump of User Object (clean, with-meta):' . $eos;
|
||||
var_dump($obj->widget->getData());
|
||||
|
||||
echo 'Dump of User Object (not-clean, with-meta):' . $eos;
|
||||
var_dump($obj->widget->getData(false));
|
||||
23
stubs/testEmaiValidation.php
Normal file
23
stubs/testEmaiValidation.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
$file = basename(__FILE__);
|
||||
$errors = [];
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_USERS,
|
||||
META_CLIENT => CLIENT_SYSTEM,
|
||||
META_EVENT_GUID => guid(),
|
||||
META_DO_CACHE => 0
|
||||
];
|
||||
$obj = new gacUsers($meta);
|
||||
if (!$obj->status)
|
||||
exit (sprintf( INFO_LOC, $file, __LINE__) . TEMPLATE_CLASS_USERS);
|
||||
$validEmail = 'mshallop@maplehillchaos.com';
|
||||
$invalidEmail = 'gooberJoe@argle';
|
||||
$complexEmail = 'mike@sales.executives.goodgirl.jewelery';
|
||||
|
||||
$obj->checkWBL($validEmail);
|
||||
|
||||
echo $validEmail . 'is ' . ($obj->status) ? '' : 'in' . 'valid with state: ' . $obj->state . $eos;
|
||||
|
||||
echo $eos . $eos . 'program ends... ' . $eos . $eos;
|
||||
37
stubs/testJSONHandler.php
Normal file
37
stubs/testJSONHandler.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mshallop
|
||||
* Date: 4/15/19
|
||||
* Time: 11:23 AM
|
||||
*/
|
||||
|
||||
// initialization
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
$errors = [];
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_TEST_MONGO,
|
||||
META_CLIENT => CLIENT_CLIENT,
|
||||
META_EVENT_GUID => guid(),
|
||||
META_SYSTEM_NOTES => basename(__FILE__)
|
||||
];
|
||||
|
||||
// instantiate a test class and generate some test data
|
||||
$objTest = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, '',$errors);
|
||||
if (!$objTest->status)
|
||||
exit (ERROR_TEMPLATE_INSTANTIATE . TEMPLATE_CLASS_TEST_MONGO);
|
||||
/** @var $widget gatTestMongo */
|
||||
$widget = $objTest->widget;
|
||||
$testData = $widget->template->buildTestData(100);
|
||||
foreach ($testData as &$record) {
|
||||
$record[CM_TST_TOKEN] = guid();
|
||||
$record[CM_TST_FIELD_TEST_CDATE] = time();
|
||||
$record[CM_TST_FIELD_TEST_STATUS] = STATUS_ACTIVE;
|
||||
}
|
||||
|
||||
$cacheString = jsonHandler($testData, JSON_DIR_ENC, $errors, false);
|
||||
if (is_null($cacheString))
|
||||
exit('error processing json data - check logs');
|
||||
$length = strlen($cacheString);
|
||||
echo 'cache string is ' . strval($length/1024) . ' Kbytes long';
|
||||
74
stubs/testLogger.php
Normal file
74
stubs/testLogger.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mshallop
|
||||
* Date: 7/6/17
|
||||
* Time: 2:02 PM
|
||||
*/
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_LOGS,
|
||||
META_CLIENT => CLIENT_SYSTEM
|
||||
];
|
||||
$errors = array();
|
||||
$foo = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, '', $errors);
|
||||
|
||||
/** @var gacMongoDB $bar */
|
||||
$bar = $foo->widget;
|
||||
//$bar->logger->metrics('metrics test test check one two', 0.00123, $errors);
|
||||
|
||||
// find({ level_log: { $eq : "warning" }})
|
||||
$query = [
|
||||
LOG_LEVEL => [
|
||||
OPERAND_NULL => [
|
||||
OPERATOR_EQ => [ "warning" ]
|
||||
]
|
||||
]
|
||||
];
|
||||
$mongoQuery = $bar->gwValidateQuery($query);
|
||||
//if (empty($mongoQuery))
|
||||
// var_dump($bar->eventMessages);
|
||||
//else
|
||||
// var_dump($mongoQuery);
|
||||
|
||||
|
||||
// find({ $or : [ { level_log : {$eq : 'warning'}}, {level_log: {$eq: 'fatal'}}]})
|
||||
$query = [
|
||||
LOG_LEVEL => [
|
||||
OPERAND_OR => [
|
||||
OPERATOR_EQ => [ "warning", "fatal" ]
|
||||
]
|
||||
]
|
||||
];
|
||||
$mongoQuery = $bar->gwValidateQuery($query);
|
||||
//if (empty($mongoQuery))
|
||||
// var_dump($bar->eventMessages);
|
||||
//else
|
||||
// var_dump($mongoQuery);
|
||||
|
||||
|
||||
/*
|
||||
* find({ $or : [
|
||||
* { $or : [ { level_log: { $eg : 'warning'}}, {level_log: {$eg: 'fatal'}} ] },
|
||||
* { $gte : { levelValue_log : { $gte: 3 }}}
|
||||
* ]
|
||||
*/
|
||||
$query = [
|
||||
LOG_LEVEL => [ OPERAND_OR => [ OPERATOR_EQ => ['warning', 'fatal']]], // same as above
|
||||
LOG_VALUE => [ OPERAND_NULL => [ OPERATOR_GTE => [3]]],
|
||||
OPERAND_OR => null
|
||||
];
|
||||
$mongoQuery = $bar->gwValidateQuery($query);
|
||||
$bar->logger->debug('message DEBUG');
|
||||
$bar->logger->info('message INFO');
|
||||
$bar->logger->data('message DATA');
|
||||
$bar->logger->error('message ERROR');
|
||||
$bar->logger->warn('message WARN');
|
||||
$bar->logger->fatal('message FATAL');
|
||||
$bar->logger->metrics('message METRICS', 0.226622);
|
||||
|
||||
//if (empty($mongoQuery))
|
||||
// var_dump($bar->eventMessages);
|
||||
//else
|
||||
// var_dump($mongoQuery);
|
||||
37
stubs/testLogging.php
Normal file
37
stubs/testLogging.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
/*
|
||||
* what we are testing is connecting to the new log channel,
|
||||
* posting a message to the channel,
|
||||
* so that we can see what brokers picked-up the message...
|
||||
*
|
||||
*/
|
||||
|
||||
$errors = [];
|
||||
// instantiate a logger client
|
||||
$logger = new gacErrorLogger();
|
||||
if (!$logger->status) die(ERROR_FAILED_TO_INSTANTIATE . RESOURCE_LOGGER);
|
||||
$meta = [
|
||||
META_CLIENT => CLIENT_SYSTEM, // back-door the meta-data checks
|
||||
META_LIMIT => 1,
|
||||
META_TEMPLATE => TEMPLATE_CLASS_GRAPHS,
|
||||
META_TEMPLATE => TEMPLATE_CLASS_TEST_PDO,
|
||||
META_CLIENT_IP => STRING_SESSION_HOME, // required
|
||||
META_EVENT_GUID => guid() // simulate a broker event by generating the event guid
|
||||
];
|
||||
$objTest = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, '', $errors);
|
||||
|
||||
// this next part just does a non-broker fetch of a single record so that we can fire-off a metrics-fetch event
|
||||
$meta[META_TEMPLATE] = TEMPLATE_CLASS_TEST_MONGO;
|
||||
$logger->fatal(STRING_TEST);
|
||||
// fetch a test record so that we create a metrics event
|
||||
// set up the data payloads
|
||||
$objTest = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, '', $errors);
|
||||
if (!$objTest->status) die(ERROR_FAILED_TO_INSTANTIATE . $meta[META_TEMPLATE]);
|
||||
$widget = $objTest->widget;
|
||||
$query = null;
|
||||
$request = [BROKER_DATA => [ STRING_QUERY_DATA => $query]];
|
||||
$widget->_fetchRecords($request);
|
||||
if (!$widget->status) var_export($widget->eventMessages);
|
||||
echo 'done' . PHP_EOL;
|
||||
68
stubs/testMigrations.php
Normal file
68
stubs/testMigrations.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* testMigration() --- test stub
|
||||
*
|
||||
* used to test the migration process by submitting a request (instantiating the class submits the request) either
|
||||
* as an object or as a broker event. If we submit the request as an object, we can use the debugger to trace the
|
||||
* code flow. Once this is solid, turn on the broker processing so we can evaluate the broker's ability to handle
|
||||
* the request.
|
||||
*
|
||||
* @author mike@givingassistant.org
|
||||
* @version 1.0
|
||||
*
|
||||
* HISTORY:
|
||||
* ========
|
||||
* 02-21-18 mks _INF-139: original coding
|
||||
*
|
||||
*/
|
||||
|
||||
// load the namaste environment
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
const OBJECT = 1;
|
||||
const BROKER = 2;
|
||||
|
||||
// if processing is OBJECT, we can use the debugger
|
||||
// if processing is BROKER, event is passed to migration broker
|
||||
$processing = OBJECT;
|
||||
|
||||
|
||||
// set up the data payloads
|
||||
$meta = [
|
||||
META_CLIENT => CLIENT_SYSTEM,
|
||||
META_CLIENT_IP => STRING_SESSION_HOME,
|
||||
META_EVENT_GUID => guid(), // simulate a broker event by generating the event guid
|
||||
META_LIMIT => 1, // limit the deletes to deleting just the last record created
|
||||
];
|
||||
|
||||
$brokerData = [
|
||||
MIGRATION_SOURCE_SCHEMA => STRING_MYSQL,
|
||||
MIGRATION_SOURCE_TABLE => 'product_registrations',
|
||||
MIGRATION_DEST_SCHEMA => STRING_MYSQL, // either STRING_MYSQL or STRING_MONGO
|
||||
// MIGRATION_DEST_TABLE => TEMPLATE_CLASS_PRODUCT_REG,
|
||||
MIGRATION_DEST_TABLE => TEMPLATE_CLASS_PROD_REGS,
|
||||
MIGRATION_FILTER_SOFT_DELETES => 0, // if 1: soft deleted records will not be imported
|
||||
MIGRATION_FILTER_PARTIALS => 0, // if 1: a record will not be imported if a field fails validation
|
||||
MIGRATION_TEST_MODE => 0 // if 1: no records will be migrated, test-report generated
|
||||
];
|
||||
|
||||
// submit the request
|
||||
if ($processing == OBJECT) {
|
||||
// submit the request at the object level for debugging
|
||||
$testObject = new gacMigrations($brokerData, $meta);
|
||||
var_export( ($testObject->status) ? $testObject->migrationReport : $testObject->errorStack );
|
||||
if (is_object($testObject)) $testObject->__destruct();
|
||||
unset($testObject);
|
||||
} else {
|
||||
// submit the request to the broker
|
||||
$bc = new gacBrokerClient(BROKER_QUEUE_M, basename(__FILE__) . COLON_NS . __LINE__);
|
||||
$request = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_MIGRATION,
|
||||
BROKER_DATA => $brokerData,
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
$payload = gzcompress(json_encode($request));
|
||||
$response = json_decode(gzuncompress($bc->call($payload)), true);
|
||||
var_export($response);
|
||||
if (is_object($bc)) $bc->__destruct();
|
||||
unset($bc);
|
||||
}
|
||||
584
stubs/testMongo.php
Normal file
584
stubs/testMongo.php
Normal file
@@ -0,0 +1,584 @@
|
||||
<?php
|
||||
/**
|
||||
* testMongo.php -- class-level test stub to validate mongo CRUD operations
|
||||
*
|
||||
* NOTE:
|
||||
* -----
|
||||
* as of 3-11-19, you have to process the meta-data payload through validateMetaData() in functions.php before
|
||||
* submitting the payload to a class CRUD method, such as _fetchRecords().
|
||||
*
|
||||
*/
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
// operations supported in this test script:
|
||||
const OP_CREATE = 1;
|
||||
const OP_FETCH = 2;
|
||||
const OP_UPDATE = 3;
|
||||
const OP_DELETE = 4;
|
||||
const OP_SUBC_PUSH = 5;
|
||||
const OP_SUBC_DEL = 6;
|
||||
const OP_FETCH_LIMIT = 7;
|
||||
const OP_FETCH_ALL = 8;
|
||||
const OP_FETCH_BY_GUID = 9;
|
||||
const OP_AUDIT_ROLLBACK = 10;
|
||||
const OP_BAD_UPDATE = 11;
|
||||
const OP_UPDATE_MANY = 12;
|
||||
const OP_UPDATE_IN = 13;
|
||||
const OP_SUBC_FETCH = 14;
|
||||
const OP_TOK_UPD = 15; // token update
|
||||
const OP_SMAX_CLIENT = 16; // smax client instantiation simulation
|
||||
|
||||
$thisOperation = OP_CREATE;
|
||||
|
||||
// instantiate
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_TEST_MONGO,
|
||||
META_CLIENT => CLIENT_CLIENT,
|
||||
META_CLIENT_IP => STRING_SESSION_HOME,
|
||||
META_EVENT_GUID => guid(), // simulate a broker event by generating the event guid
|
||||
];
|
||||
echo 'Event GUID: ' . $meta[META_EVENT_GUID] . PHP_EOL;
|
||||
$jayne = "Ten percent of nothin' is ... let me do the math here ... nothin' into nothin' ... carry the nothin' ... ";
|
||||
$errors = array();
|
||||
// turn off mongo option
|
||||
// gasConfig::$settings[CONFIG_DATABASE][CONFIG_DATABASE_MONGODB][CONFIG_DATABASE_MONGODB_ENABLED] = 0;
|
||||
$objTest = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, '', $errors);
|
||||
if (!$objTest->status) {
|
||||
var_export($objTest);
|
||||
exit;
|
||||
}
|
||||
/** @var gatTestMongo $objMongoTest->template */
|
||||
/** @var gacMongoDB $objMongoTest */
|
||||
$objMongoTest = $objTest->widget;
|
||||
$objTest->__destruct();
|
||||
unset($objTest);
|
||||
//$objMongoTest->logger->info(basename(__FILE__) . AT . __LINE__);
|
||||
|
||||
//$objMongoTest->logger->warn('this is a test message');
|
||||
// ok - now we have a native class object (widget) and we can do CRUD stuff..
|
||||
// invoke the template method to generate a new data set of test data
|
||||
switch ($thisOperation) {
|
||||
case OP_CREATE :
|
||||
$targetNumber = 1; // adjust this value to test with differing amounts of records
|
||||
$testData = $objMongoTest->template->buildTestData($targetNumber);
|
||||
$meta[META_DO_CACHE] = false;
|
||||
// insert a bogus sub-collection field
|
||||
$testData[0][CM_TST_FIELD_TEST_SUBC][STRING_WH_SETTINGS] = 'you should not see this value stored in the record ever';
|
||||
$brokerPayload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => $testData,
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
if (!validateMetaData($brokerPayload, $errors))
|
||||
exit('meta data validation failed');
|
||||
$objMongoTest->_createRecord($brokerPayload[BROKER_DATA]);
|
||||
if ($objMongoTest->status) {
|
||||
if (gasCache::mapOutboundPayload($objMongoTest, $errors)) {
|
||||
var_export($objMongoTest->getCK());
|
||||
echo $eos;
|
||||
} else {
|
||||
var_export($objMongoTest->eventMessages);
|
||||
echo $eos;
|
||||
}
|
||||
} else {
|
||||
var_export($objMongoTest->eventMessages);
|
||||
echo $eos . ERROR_NOSQL_CREATE . $eos;
|
||||
}
|
||||
break;
|
||||
|
||||
case OP_SMAX_CLIENT :
|
||||
// use the GA client which should already be in the SMAXAPI collection
|
||||
$clientToken = '79344859-5403-1556-7663-4E34D6B4CBE4'; // ga token
|
||||
$clientToken = '136EA67A-B1E2-0A4B-2BD8-EE34D39DFDE1'; // pl token
|
||||
$meta[CLIENT_AUTH_TOKEN] = $clientToken;
|
||||
$meta[META_CLIENT] = CLIENT_API_USER;
|
||||
$meta[META_TEMPLATE] = TEMPLATE_PL_DONORS;
|
||||
$obj = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, '', $errors);
|
||||
if (!$obj->status) exit(ERROR_FACTORY_LOAD_BROKER . basename(__FILE__));
|
||||
exit('successful instantiation of a priceline class by a priceline client');
|
||||
break;
|
||||
|
||||
case OP_FETCH :
|
||||
// let's do a fetch of records now - we want records where the string field hasn't been set to $jayne
|
||||
// set the number of records to fetch...
|
||||
$targetNumber = 5;
|
||||
$objMongoTest->addMeta(META_LIMIT, $targetNumber);
|
||||
// let's also set the skip meta value to ensure that skip is working correctly
|
||||
$objMongoTest->addMeta(META_SKIP, 5);
|
||||
// disable cache for testing:
|
||||
$objMongoTest->addMeta(META_DONUT_FILTER, 1);
|
||||
// set-up the query to fetch records where the string is not set to $jayne
|
||||
// and sort in descending (LIFO) order of the created-date
|
||||
$query = [ CM_TST_FIELD_TEST_STRING => [ OPERAND_NULL => [ OPERATOR_DNE => [$jayne] ] ] ];
|
||||
$sort = [ CM_TST_FIELD_TEST_CDATE => STRING_SORT_DESC ];
|
||||
// enable the next line to test projection filtering
|
||||
// $projection = [ CM_TST_FIELD_TEST_DOUBLE ];
|
||||
// build the request payload
|
||||
$request = [ STRING_QUERY_DATA => $query, STRING_SORT_DATA => $sort ];
|
||||
// $request = [ STRING_QUERY_DATA => $query, STRING_SORT_DATA => $sort, STRING_RETURN_DATA => $projection ];
|
||||
$brokerPayload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
STRING_SERVICE => ENV_APPSERVER,
|
||||
BROKER_DATA => $request,
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
if (!validateMetaData($brokerPayload, $errors)) exit('meta data validation failed');
|
||||
$objMongoTest->_fetchRecords($request);
|
||||
// cacheMap the outbound payload
|
||||
$errors = [];
|
||||
if (gasCache::mapOutboundPayload($objMongoTest, $errors)) {
|
||||
var_export($objMongoTest->getCK());
|
||||
echo $eos;
|
||||
} else {
|
||||
var_export(array_merge($objMongoTest->eventMessages, $errors));
|
||||
echo $eos;
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
|
||||
case OP_UPDATE_IN :
|
||||
$updateString = 'Saw your dork mobile in the parking lot - what does it get, like four miles to the gallon?';
|
||||
// first, fetch the first 10 records with an active status
|
||||
$query = [
|
||||
CM_TST_FIELD_TEST_STATUS => [ OPERAND_NULL => [ OPERATOR_EQ => [ STATUS_ACTIVE ]]],
|
||||
CM_TST_FIELD_TEST_STRING => [ OPERAND_NULL => [ OPERATOR_DNE => [ $updateString ]]],
|
||||
OPERAND_AND => null
|
||||
];
|
||||
$objMongoTest->addMeta(META_LIMIT, 5);
|
||||
$payload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => [ STRING_QUERY_DATA => $query, STRING_RETURN_DATA => [ CM_TST_TOKEN ]],
|
||||
BROKER_META_DATA => $objMongoTest->getMetaDataPayload()
|
||||
];
|
||||
if (!validateMetaData($payload, $errors)) exit(ERROR_META_VALIDATION_SECOND_PASS);
|
||||
@$objMongoTest->addMeta(META_DO_CACHE, false);
|
||||
$objMongoTest->_fetchRecords($payload[BROKER_DATA]);
|
||||
// we're testing the cache-bypass feature here in this next call
|
||||
if (!gasCache::mapOutboundPayload($objMongoTest, $errors)) {
|
||||
exit(ERROR_CACHE_MAP_FAIL . ' outbound payload');
|
||||
}
|
||||
if (!$objMongoTest->status) {
|
||||
var_export($objMongoTest->eventMessages);
|
||||
exit;
|
||||
}
|
||||
$data = $objMongoTest->getData();
|
||||
$inData = null;
|
||||
foreach ($data as $record)
|
||||
foreach ($record as $k => $v)
|
||||
$inData[] = $v;
|
||||
// now that have the list of 10 records to update...generate the update command
|
||||
$query = [ CM_TST_TOKEN => [ OPERAND_NULL => [ OPERATOR_IN => [ $inData ]]]];
|
||||
$payload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_UPDATE,
|
||||
BROKER_DATA => [
|
||||
STRING_QUERY_DATA => $query,
|
||||
STRING_UPDATE_DATA => [ CM_TST_FIELD_TEST_STRING => $updateString ]
|
||||
],
|
||||
BROKER_META_DATA => $objMongoTest->getMetaDataPayload()
|
||||
];
|
||||
if (!validateMetaData($payload, $errors)) exit(ERROR_META_VALIDATION_SECOND_PASS);
|
||||
$objMongoTest->_updateRecord($payload[BROKER_DATA]);
|
||||
echo ($objMongoTest->status) ? 'success' : 'fail' . PHP_EOL;
|
||||
break;
|
||||
|
||||
case OP_FETCH_BY_GUID :
|
||||
// for this, you need to provide the GUID string of the record you wish to fetch
|
||||
// this section is provided to test for loading a record via instantiation
|
||||
$guid = '93241A58-B375-A31C-1429-2F185AFFD01A';
|
||||
if (empty($guid) or !validateGUID($guid)) {
|
||||
echo 'Missing or invalid guid for fetch by guid test' . $eos;
|
||||
exit;
|
||||
}
|
||||
// delete the pre-existing object and re-create so we can instantiate with a guid
|
||||
if (is_object($objMongoTest)) {
|
||||
$objMongoTest->__destruct();
|
||||
unset($objMongoTest);
|
||||
$objTest = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, $guid, $errors);
|
||||
if (!$objTest->status) {
|
||||
var_export($objTest);
|
||||
exit;
|
||||
}
|
||||
/** @var gatTestMongo $objMongoTest->template */
|
||||
/** @var gacMongoDB $objMongoTest */
|
||||
$objMongoTest = $objTest->widget;
|
||||
$objTest->__destruct();
|
||||
unset($objTest);
|
||||
}
|
||||
$query = [ CM_TST_TOKEN => [ OPERAND_NULL => [ OPERATOR_EQ => [ $guid ]]]];
|
||||
$request = [ STRING_QUERY_DATA => $query ];
|
||||
$brokerPayload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => $request,
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
validateMetaData($brokerPayload, $errors);
|
||||
$objMongoTest->_fetchRecords($brokerPayload[BROKER_DATA]);
|
||||
if (!$objMongoTest->status) {
|
||||
var_export($objMongoTest->eventMessages);
|
||||
echo $eos;
|
||||
exit;
|
||||
}
|
||||
$queryResults = gasCache::mapOutboundPayload($objMongoTest, $errors);
|
||||
var_export($objMongoTest->getData());
|
||||
exit;
|
||||
break;
|
||||
|
||||
case OP_AUDIT_ROLLBACK :
|
||||
$query = null;
|
||||
$errors = [];
|
||||
$retData = [];
|
||||
if (is_object($objMongoTest)) $objMongoTest->__destruct();
|
||||
unset($objMongoTest);
|
||||
|
||||
// pre-determined DB_TOKEN of targeted audit record
|
||||
$queryData = [ STRING_KEY => "4AF69A2C-DD4D-CE27-D692-6CA845B2380D" ];
|
||||
$meta[META_USER_INFO] = basename(__FILE__);
|
||||
$meta[META_SYSTEM_NOTES] = 'testing journal recovery';
|
||||
$meta[META_TEMPLATE] = TEMPLATE_CLASS_AUDIT;
|
||||
|
||||
// instantiate the audit record
|
||||
$objFactory = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, $queryData[STRING_KEY], $errors);
|
||||
if (!$objFactory->status) {
|
||||
echo ERROR_FACTORY_LOAD_BROKER . TEMPLATE_CLASS_AUDIT . $eos;
|
||||
var_export($objFactory->eventMessages);
|
||||
exit;
|
||||
}
|
||||
$objAudit = $objFactory->widget;
|
||||
if (is_object($objFactory)) $objFactory->__destruct();
|
||||
unset($objFactory);
|
||||
|
||||
// launch the audit process
|
||||
$startTime = gasStatic::doingTime();
|
||||
$rc = $objAudit->restoreAuditRecord($retData);
|
||||
$totalTime = gasStatic::doingTime($startTime);
|
||||
if ($rc === true) echo 'Audit record recovered in: ' . (string) $totalTime . ' seconds' . $eos;
|
||||
elseif (is_null($rc)) echo 'Audit method returned null' . $eos;
|
||||
else echo 'Audit request failed';
|
||||
if (!is_null($rc))
|
||||
var_export($rc);
|
||||
else
|
||||
var_export($objAudit->eventMessages);
|
||||
exit;
|
||||
break;
|
||||
|
||||
case OP_FETCH_LIMIT :
|
||||
$query = null;
|
||||
$objMongoTest->addMeta(META_LIMIT, 1);
|
||||
$request = [ BROKER_REQUEST => BROKER_REQUEST_FETCH, STRING_QUERY_DATA => $query, BROKER_META_DATA => $meta ];
|
||||
$objMongoTest->_fetchRecords($request);
|
||||
if ($objMongoTest->status) {
|
||||
echo $objMongoTest->strQuery . $eos;
|
||||
} else {
|
||||
var_export($objMongoTest->eventMessages);
|
||||
echo $eos;
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
|
||||
case OP_FETCH_ALL :
|
||||
$query = null;
|
||||
if (isset($meta[META_LIMIT])) unset($meta[META_LIMIT]);
|
||||
$request = [ BROKER_REQUEST => BROKER_REQUEST_FETCH, STRING_QUERY_DATA => $query, BROKER_META_DATA => $meta ];
|
||||
$objMongoTest->_fetchRecords($request);
|
||||
if ($objMongoTest->status) {
|
||||
echo $objMongoTest->strQuery . $eos;
|
||||
} else {
|
||||
var_export($objMongoTest->eventMessages);
|
||||
echo $eos;
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
|
||||
case OP_TOK_UPD :
|
||||
$token = '6CEA2DA3-F39E-873E-0F74-73C930159156';
|
||||
$badToken = '6CEA2DA3-F39E-873E-0F74-73C930159150';
|
||||
$badField = 'argle';
|
||||
$badValue = 123;
|
||||
$uMeta = $meta;
|
||||
$uMeta[META_TEMPLATE] = TEMPLATE_CLASS_SMAXAPI;
|
||||
$uMeta[META_CLIENT] = CLIENT_API;
|
||||
$errors = [];
|
||||
$widget = new gacFactory($uMeta, FACTORY_EVENT_NEW_CLASS, '', $errors);
|
||||
if ($widget->status) {
|
||||
/** @var gacMongoDB $objToken */
|
||||
$objToken = $widget->widget;
|
||||
} else {
|
||||
exit(ERROR_TEMPLATE_INSTANTIATE . TEMPLATE_CLASS_SMAXAPI);
|
||||
}
|
||||
$data = [
|
||||
STRING_QUERY_DATA => [ STRING_KEY => [ OPERAND_NULL => [ OPERATOR_EQ => [ $badToken ]]]],
|
||||
STRING_UPDATE_DATA => [ 'givva_employee_name' => 'Scott Everson' ]
|
||||
];
|
||||
$objToken->_updateRecord($data);
|
||||
var_export($objToken->eventMessages);
|
||||
if (is_object($widget)) $widget->__destruct();
|
||||
if (is_object($objToken)) $objToken->__destruct();
|
||||
unset($objToken, $widget);
|
||||
break;
|
||||
|
||||
case OP_UPDATE :
|
||||
// if you want to test update using a cached class, but not using the cachemap variables, then provide a valid
|
||||
// token GUID for the record to be updated here -- use $query2 and $update2 as your payload parameters.
|
||||
$token = '5074D1E8-C4B6-559B-92A6-09C945FC4A4A';
|
||||
$newString = "Ten percent of nothin' is ... let me do the math here ... nothin' into nothin' ... carry the nothin' ... ";
|
||||
|
||||
// plan here is to fetch the first active record, nothing fancy:
|
||||
$recordLimit = 1; // adjust this value to set the number of records that will be updated
|
||||
// fetch query looking for active records who's string field has not been updated
|
||||
$query = [
|
||||
CM_TST_FIELD_TEST_STATUS => [ OPERAND_NULL => [ OPERATOR_EQ => [ STATUS_ACTIVE ] ] ],
|
||||
CM_TST_FIELD_TEST_STRING => [ OPERAND_NULL => [ OPERATOR_DNE => [ $newString ]] ],
|
||||
OPERAND_AND => null
|
||||
];
|
||||
// update query using actual column names
|
||||
$query2 = [
|
||||
DB_TOKEN => [ OPERAND_NULL => [ OPERATOR_EQ => [ $token ]]],
|
||||
OPERAND_AND => null
|
||||
];
|
||||
// let's limit the number of records returned to 10 -- normally, this query returns about a 100 records
|
||||
// using the current data set...
|
||||
$objMongoTest->addMeta(META_LIMIT, $recordLimit);
|
||||
$request = [ STRING_QUERY_DATA => $query ];
|
||||
$update = [ CM_TST_FIELD_TEST_STRING => $newString, CM_TST_FIELD_TEST_INT => intval(mt_rand(1,100)) ];
|
||||
$update2 = [ DB_STATUS => STATUS_DELETED ];
|
||||
// next field should generate an error b/c we can't update a protected field
|
||||
// $update = [ CM_TST_FIELD_TEST_CDATE => intval(mt_rand(1,100)) ];
|
||||
|
||||
// use either $query/$update or $query2/$update2 in the payload
|
||||
// $request = [ STRING_QUERY_DATA => $query, STRING_UPDATE_DATA => $update];
|
||||
$request = [ STRING_QUERY_DATA => $query, STRING_UPDATE_DATA => $update];
|
||||
$objMongoTest->addMeta(META_LIMIT, 1);
|
||||
// enable the following line if you want to skip caching of the return payload
|
||||
$objMongoTest->addMeta(META_DO_CACHE, false);
|
||||
$payload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_UPDATE,
|
||||
BROKER_DATA => $request,
|
||||
BROKER_META_DATA => $objMongoTest->getMetaDataPayload()
|
||||
];
|
||||
if (!validateMetaData($payload, $errors)) {
|
||||
echo ERROR_META_VALIDATION_SECOND_PASS;
|
||||
exit;
|
||||
}
|
||||
$objMongoTest->_updateRecord($payload[BROKER_DATA]);
|
||||
if ($objMongoTest->status) {
|
||||
$queryResults = gasCache::mapOutboundPayload($objMongoTest, $errors);
|
||||
if ($objMongoTest->useCache) {
|
||||
var_export($objMongoTest->getCK());
|
||||
echo $eos;
|
||||
} else {
|
||||
var_export($objMongoTest->getData());
|
||||
echo $eos;
|
||||
}
|
||||
} else {
|
||||
var_export($objMongoTest->eventMessages);
|
||||
echo $eos;
|
||||
}
|
||||
break;
|
||||
|
||||
case OP_UPDATE_MANY:
|
||||
// replicate the unit-test query -- where we're just updating the first X active records
|
||||
$query = [
|
||||
CM_TST_FIELD_TEST_INT => [ OPERAND_NULL => [ OPERATOR_EQ => [ 4 ]]],
|
||||
CM_TST_FIELD_TEST_BOOL => [ OPERAND_NULL => [ OPERATOR_EQ => [ false ]]],
|
||||
OPERAND_AND => null
|
||||
];
|
||||
if (isset($meta[META_LIMIT])) unset($meta[META_LIMIT]);
|
||||
$newString = "Dwight Schrute's Gym for Muscles";
|
||||
$updateData = [ CM_TST_FIELD_TEST_STRING => $newString ];
|
||||
$payload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_UPDATE,
|
||||
BROKER_DATA => [
|
||||
STRING_QUERY_DATA => $query,
|
||||
STRING_UPDATE_DATA => $updateData
|
||||
],
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
if (!validateMetaData($payload, $errors)) {
|
||||
echo ERROR_META_VALIDATION_SECOND_PASS;
|
||||
exit;
|
||||
}
|
||||
$objMongoTest->addMeta(META_LIMIT, 10);
|
||||
$objMongoTest->_updateRecord($payload[BROKER_DATA]);
|
||||
$errors = null;
|
||||
$queryResults = gasCache::mapOutboundPayload($objMongoTest, $errors);
|
||||
$x = 1;
|
||||
break;
|
||||
|
||||
case OP_BAD_UPDATE:
|
||||
$errors = array();
|
||||
// first, fetch any active record
|
||||
$query = [ CM_TST_FIELD_TEST_STATUS => [ OPERAND_NULL => [ OPERATOR_EQ => [ STATUS_ACTIVE ]]]];
|
||||
$objMongoTest->addMeta(META_LIMIT, 1);
|
||||
$payload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => [ STRING_QUERY_DATA => $query, STRING_RETURN_DATA => [ CM_TST_TOKEN ] ],
|
||||
BROKER_META_DATA => $objMongoTest->getMetaDataPayload()
|
||||
];
|
||||
if (!validateMetaData($payload, $errors)) exit('meta data validation failed for fetch');
|
||||
$objMongoTest->_fetchRecords($payload[BROKER_DATA]);
|
||||
@$objMongoTest->removeMeta(META_LIMIT);
|
||||
|
||||
// now that we have our record...first, get the token...
|
||||
if (!$objMongoTest->status) exit('failed to fetch record for update');
|
||||
$token = $objMongoTest->getColumn(DB_TOKEN);
|
||||
|
||||
// build the update query using the token as the search discriminant
|
||||
$query = [ CM_TST_TOKEN => [ OPERAND_NULL => [ OPERATOR_EQ => [ $token ]]]];
|
||||
// build the update query using a protected field -- doesn't matter since it should be rejected/dropped
|
||||
$update = [ CM_TST_FIELD_TEST_CDATE => STRING_DATA ];
|
||||
$request = [
|
||||
STRING_QUERY_DATA => $query,
|
||||
STRING_UPDATE_DATA => $update
|
||||
];
|
||||
$payload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_UPDATE,
|
||||
BROKER_DATA => $request,
|
||||
BROKER_META_DATA => $objMongoTest->getMetaDataPayload()
|
||||
];
|
||||
if (!validateMetaData($payload, $errors)) exit('meta data validation failed for update');
|
||||
$objMongoTest->_updateRecord($payload[BROKER_DATA]);
|
||||
$x = 1;
|
||||
break;
|
||||
|
||||
case OP_DELETE :
|
||||
$originalMeta = $objMongoTest->getMetaDataPayload();
|
||||
// target any record where the test-string is set to $jayne
|
||||
$query = [ CM_TST_FIELD_TEST_STRING => [ OPERAND_NULL => [ OPERATOR_EQ => [$jayne]]]];
|
||||
$query = [ CM_TOKEN => [ OPERAND_NULL => [ OPERATOR_EQ => [ '362C8565-8D39-C619-7800-DDB025292AC2' ]]]];
|
||||
// delete only one record
|
||||
$objMongoTest->addMeta(META_LIMIT, 1);
|
||||
// $objMongoTest->useDeletes = true; // turn on hard deletes
|
||||
$objMongoTest->_deleteRecord([STRING_QUERY_DATA => $query]);
|
||||
if ($objMongoTest->status) {
|
||||
$queryResults = gasCache::mapOutboundPayload($objMongoTest, $errors);
|
||||
if ($objMongoTest->useCache) {
|
||||
var_export($objMongoTest->getCK());
|
||||
echo $eos;
|
||||
} else {
|
||||
var_export($objMongoTest->getData());
|
||||
echo $eos;
|
||||
}
|
||||
} else {
|
||||
var_export($objMongoTest->eventMessages);
|
||||
echo $eos;
|
||||
}
|
||||
break;
|
||||
|
||||
case OP_SUBC_PUSH :
|
||||
// set the following variable to true if you want to mimic the unit test: testNegativeSubCollectionInsert()
|
||||
// this tests exceeding the max_record count on sub-collection inserts...
|
||||
$negativeTest = false;
|
||||
// first, fetch any active record
|
||||
$query = [ CM_TST_FIELD_TEST_STATUS => [ OPERAND_NULL => [ OPERATOR_EQ => [ STATUS_ACTIVE ]]]];
|
||||
$objMongoTest->addMeta(META_LIMIT, 1);
|
||||
$payload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => [ STRING_QUERY_DATA => $query, STRING_RETURN_DATA => [ CM_TST_TOKEN ] ],
|
||||
BROKER_META_DATA => $objMongoTest->getMetaDataPayload()
|
||||
];
|
||||
if (!validateMetaData($payload, $errors)) exit('meta data validation failed for fetch');
|
||||
$objMongoTest->_fetchRecords($payload[BROKER_DATA]);
|
||||
@$objMongoTest->removeMeta(META_LIMIT);
|
||||
|
||||
// now that we have our record...first, get the token...
|
||||
if (!$objMongoTest->status) exit('failed to fetch record for update');
|
||||
$pkey = $objMongoTest->getColumn(DB_TOKEN);
|
||||
$field = CM_TST_FIELD_TEST_SUBC; // the cache-mapped name of the field
|
||||
$newSubCRecord = [
|
||||
CM_TST_FIELD_TEST_INT => 22,
|
||||
CM_TST_FIELD_TEST_DOUBLE => 22.22,
|
||||
CM_TST_FIELD_TEST_STRING => 'twenty-two',
|
||||
CM_TST_FIELD_TEST_BOOL => true
|
||||
];
|
||||
|
||||
// if we're negative-testing, then load-up the $records array with more records than max allowed
|
||||
if ($negativeTest) {
|
||||
$qrl = intval(gasConfig::$settings[CONFIG_DATABASE][CONFIG_DATABASE_QUERY_RECORD_LIMIT]);
|
||||
$recCount = 1 + $qrl;
|
||||
for ($index = 0; $index < $recCount; $index++) $records[] = $newSubCRecord;
|
||||
} else {
|
||||
$records = [$newSubCRecord];
|
||||
}
|
||||
|
||||
$requestPayload = [ STRING_GUID_KEY => $pkey, STRING_SUBC_FIELD => $field, STRING_DATA => $records ];
|
||||
// what we would normally submit to a broker (for validation purposes here)
|
||||
$payload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_SUBC_CREATE,
|
||||
BROKER_DATA => $requestPayload,
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
if (!validateMetaData($payload, $errors)) {
|
||||
var_export($errors);
|
||||
exit;
|
||||
}
|
||||
$objMongoTest->pushSubCollectionEvent($payload[BROKER_DATA]);
|
||||
var_export($objMongoTest);
|
||||
echo $eos;
|
||||
break;
|
||||
|
||||
case OP_SUBC_DEL :
|
||||
$recordToken = '62294EBC-FD37-4923-64F0-1E4324EE365A';
|
||||
$subCToken = '85DFED9D-B5E8-A3B6-6A3D-DA51D690F0FB';
|
||||
$request = [
|
||||
STRING_GUID_KEY => $recordToken,
|
||||
STRING_SUBC_GUID => $subCToken,
|
||||
STRING_SUBC_FIELD => CM_TST_FIELD_TEST_SUBC
|
||||
];
|
||||
$payload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_SUBC_DELETE,
|
||||
BROKER_DATA => $request,
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
if (!validateMetaData($payload, $errors))
|
||||
exit (ERROR_META_VALIDATION_SECOND_PASS);
|
||||
$objMongoTest->popSubCollection($payload[BROKER_DATA]);
|
||||
echo 'State: ' . $objMongoTest->state . $eos;
|
||||
var_export($objMongoTest->strQuery);
|
||||
echo $eos;
|
||||
break;
|
||||
|
||||
case OP_SUBC_FETCH :
|
||||
$meta[META_LIMIT] = 1;
|
||||
$objMongoTest->addMeta(META_LIMIT, 1);
|
||||
// complex query (two sub-collection fields)
|
||||
$payload1 = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_SUBC_FETCH,
|
||||
BROKER_DATA => [
|
||||
STRING_SUBC_COL => CM_TST_FIELD_TEST_SUBC,
|
||||
STRING_SUBC_DATA => [
|
||||
CM_TST_FIELD_TEST_INT => 7,
|
||||
CM_TST_FIELD_TEST_BOOL => false
|
||||
],
|
||||
],
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
// simple query (one sub-collection field)
|
||||
$payload2 = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_SUBC_FETCH,
|
||||
BROKER_DATA => [
|
||||
STRING_SUBC_COL => CM_TST_FIELD_TEST_SUBC,
|
||||
STRING_SUBC_DATA => [ CM_TST_FIELD_TEST_INT => 7]
|
||||
],
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
|
||||
$payload = $payload1;
|
||||
|
||||
if (!validateMetaData($payload, $errors)) {
|
||||
var_export($errors);
|
||||
echo $eos;
|
||||
exit(ERROR_META_VALIDATION_SECOND_PASS);
|
||||
}
|
||||
$objMongoTest->fetchSubCollectionRecord($payload[BROKER_DATA]);
|
||||
echo $eos . 'State: ' . $objMongoTest->state . $eos;
|
||||
if ($objMongoTest->status) {
|
||||
echo $objMongoTest->strQuery . $eos;
|
||||
var_export($objMongoTest->getData());
|
||||
} else {
|
||||
echo $eos;
|
||||
var_export($objMongoTest->eventMessages);
|
||||
echo $eos;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
332
stubs/testPDO.php
Normal file
332
stubs/testPDO.php
Normal file
@@ -0,0 +1,332 @@
|
||||
<?php
|
||||
/**
|
||||
* testPDO.php -- object-oriented testing
|
||||
*/
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
const OP_CREATE = 1;
|
||||
const OP_FETCH = 2;
|
||||
const OP_UPDATE = 3;
|
||||
const OP_DELETE = 4;
|
||||
const OP_CALL_SP = 5;
|
||||
const OP_CALL_SF = 6;
|
||||
const OP_FETCH_BY_GUID = 7;
|
||||
const OP_AUDIT_RESTORE = 8;
|
||||
const OP_BAD_FETCH = 9;
|
||||
const OP_UPDATE_DELETE = 10;
|
||||
const OP_UPDATE_MANY = 11;
|
||||
const OP_FETCH_IN = 12;
|
||||
const OP_FETCH_ANY = 13;
|
||||
|
||||
$thisOperation = OP_CREATE;
|
||||
|
||||
// test that we can init a PDO connector
|
||||
//$mdbConnector = gasResourceManager::fetchResource(RESOURCE_PDO_MASTER);
|
||||
|
||||
$res = 'tPDO: ';
|
||||
$errors = array();
|
||||
$jayne = "Ten percent of nothin' is ... let me do the math here ... nothin' into nothin' ... carry the nothin' ... ";
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_TEST_PDO,
|
||||
META_CLIENT => CLIENT_CLIENT,
|
||||
META_CLIENT_IP => STRING_SESSION_HOME,
|
||||
META_EVENT_GUID => guid(), // simulate a broker event by generating the event guid
|
||||
];
|
||||
|
||||
if ($thisOperation != OP_FETCH_BY_GUID and $thisOperation != OP_AUDIT_RESTORE) {
|
||||
$objFactory = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, '', $errors);
|
||||
if (!$objFactory->status or !empty($errors)) {
|
||||
consoleLog($res, CON_ERROR, ERROR_TEMPLATE_INSTANTIATE . $meta[META_TEMPLATE]);
|
||||
foreach ($errors as $error) consoleLog($res, CON_ERROR, $error);
|
||||
exit;
|
||||
}
|
||||
/** @var gacPDO $objTest */
|
||||
$objTest = $objFactory->widget;
|
||||
if (is_object($objFactory)) $objFactory->__destruct();
|
||||
unset($objFactory);
|
||||
}
|
||||
|
||||
switch ($thisOperation) {
|
||||
case OP_CREATE :
|
||||
$data = $objTest->template->buildTestData(100, true);
|
||||
$brokerPayload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => $data,
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
if (!validateMetaData($brokerPayload, $errors)) exit('meta data validation failed');
|
||||
$objTest->_createRecord($data);
|
||||
if ($objTest->status) {
|
||||
if (gasCache::mapOutboundPayload($objTest, $errors)) {
|
||||
var_export($objTest->getCK());
|
||||
echo $eos;
|
||||
} else {
|
||||
var_export($objTest->eventMessages);
|
||||
echo $eos;
|
||||
}
|
||||
} else {
|
||||
var_export($objTest->eventMessages);
|
||||
echo $eos . ERROR_NOSQL_CREATE . $eos;
|
||||
}
|
||||
break;
|
||||
case OP_FETCH :
|
||||
$data = $objTest->template->buildTestData(1);
|
||||
//$objTest->_fetchRecords($data);
|
||||
$query = [ CM_TST_FIELD_TEST_STRING => [ OPERAND_NULL => [ OPERATOR_DNE => [ $jayne ] ] ] ];
|
||||
$projection = [ CM_TST_TOKEN, CM_TST_FIELD_TEST_STATUS ];
|
||||
$request = [ STRING_QUERY_DATA => $query, STRING_RETURN_DATA => $projection ];
|
||||
$objTest->addMeta(META_LIMIT, 1);
|
||||
$brokerPayload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => $request,
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
//$query = null;
|
||||
if (!validateMetaData($brokerPayload, $errors)) exit('meta data validation failed');
|
||||
$objTest->_fetchRecords($brokerPayload[BROKER_DATA]);
|
||||
if ($objTest->status) {
|
||||
if (gasCache::mapOutboundPayload($objTest, $errors)) {
|
||||
var_export($objTest->getCK());
|
||||
echo $eos;
|
||||
} else {
|
||||
var_export($objTest->eventMessages);
|
||||
echo $eos;
|
||||
}
|
||||
} else {
|
||||
var_export($objTest->eventMessages);
|
||||
echo $eos . ERROR_NOSQL_CREATE . $eos;
|
||||
}
|
||||
break;
|
||||
case OP_FETCH_ANY :
|
||||
$query = null;
|
||||
$objTest->addMeta(META_LIMIT,2);
|
||||
$meta[META_LIMIT] = 1;
|
||||
$request = [ STRING_QUERY_DATA => $query ];
|
||||
$brokerPayload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => $request,
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
if (!validateMetaData($brokerPayload, $errors)) exit('meta data validation failed');
|
||||
$objTest->_fetchRecords($brokerPayload[BROKER_DATA]);
|
||||
if ($objTest->status) {
|
||||
if (gasCache::mapOutboundPayload($objTest, $errors)) {
|
||||
var_export($objTest->getCK());
|
||||
echo $eos;
|
||||
} else {
|
||||
var_export($objTest->eventMessages);
|
||||
echo $eos;
|
||||
}
|
||||
} else {
|
||||
var_export($objTest->eventMessages);
|
||||
echo $eos . ERROR_NOSQL_CREATE . $eos;
|
||||
}
|
||||
break;
|
||||
case OP_FETCH_IN :
|
||||
// get any three active records;
|
||||
$query = null;
|
||||
$recordList = null;
|
||||
$projection = [ CM_TST_TOKEN ];
|
||||
$request = [ STRING_QUERY_DATA => $query, STRING_RETURN_DATA => $projection ];
|
||||
$brokerPayload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => $request,
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
$objTest->addMeta(META_LIMIT, 3);
|
||||
if (!validateMetaData($brokerPayload, $errors)) exit('meta data validation failure');
|
||||
$objTest->_fetchRecords($brokerPayload[BROKER_DATA]);
|
||||
if (!$objTest->status) {
|
||||
echo 'failed to fetch records' . PHP_EOL;
|
||||
var_export($objTest->eventMessages);
|
||||
echo PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
foreach ($objTest->getData() as $record)
|
||||
$recordList[] = $record[DB_TOKEN . $objTest->ext];
|
||||
// build the IN query
|
||||
$query = [ CM_TST_TOKEN => [ OPERAND_NULL => [ OPERATOR_IN => $recordList ]]];
|
||||
$brokerPayload = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => [ STRING_QUERY_DATA => $query ],
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
if (!validateMetaData($brokerPayload, $errors)) exit('meta data validation failure');
|
||||
$objTest->_fetchRecords($brokerPayload[BROKER_DATA]);
|
||||
if (!$objTest->status) {
|
||||
echo 'failed to fetch records' . PHP_EOL;
|
||||
var_export($objTest->eventMessages);
|
||||
echo PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
case OP_BAD_FETCH :
|
||||
$query = [ CM_TST_FIELD_TEST_STRING => [ OPERAND_NULL => [ OPERATOR_EQ => ["some string"] ] ] ];
|
||||
$request = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_FETCH,
|
||||
BROKER_DATA => [STRING_QUERY_DATA => $query],
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
if (!validateMetaData($request, $errors)) {
|
||||
var_export($errors);
|
||||
exit;
|
||||
}
|
||||
$objTest->_fetchRecords($request[STRING_QUERY_DATA]);
|
||||
if (!$objTest->status) var_export($objTest->eventMessages);
|
||||
break;
|
||||
case OP_DELETE :
|
||||
// fetch any one active record
|
||||
$query = [ CM_TST_FIELD_TEST_STATUS => [ OPERAND_NULL => [ OPERATOR_EQ => [ STATUS_ACTIVE ]]]];
|
||||
$request = [ STRING_QUERY_DATA => $query];
|
||||
$objTest->addMeta(META_DONUT_FILTER, 1);
|
||||
$objTest->addMeta(META_LIMIT, 1);
|
||||
$objTest->_fetchRecords($request);
|
||||
$data = $objTest->getData();
|
||||
$query = [ DB_TOKEN => [ OPERAND_NULL => [ OPERATOR_EQ => [ $data[0][STRING_TOKEN . $objTest->ext ]]]]];
|
||||
$data = [ STRING_QUERY_DATA => $query ];
|
||||
// $objTest->useDeletes = true; // uncomment this line to test hard-deletes
|
||||
$objTest->_deleteRecord($data);
|
||||
consoleLog($res, CON_SUCCESS, $objTest->queryResults);
|
||||
break;
|
||||
case OP_FETCH_BY_GUID :
|
||||
// for this, you need to provide the GUID string of the record you wish to fetch
|
||||
// this section is provided to test for loading a record via instantiation
|
||||
$guid = 'FBF9C067-4B20-0F6D-B8EE-FD891D80EF7C';
|
||||
if (empty($guid) or !validateGUID($guid)) {
|
||||
echo 'Missing or invalid guid for fetch by guid test' . $eos;
|
||||
exit;
|
||||
}
|
||||
// delete the pre-existing object and re-create so we can instantiate with a guid
|
||||
if (isset($objTest) and is_object($objTest)) {
|
||||
$objTest->__destruct();
|
||||
unset($objTest);
|
||||
}
|
||||
$objFactory = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, $guid, $errors);
|
||||
if (!$objFactory->status) {
|
||||
var_export($objFactory->eventMessages);
|
||||
exit;
|
||||
}
|
||||
/** @var gatTestMySQL $objTest->template */
|
||||
/** @var gacPDO $objTest */
|
||||
$objTest = $objFactory->widget;
|
||||
$objFactory->__destruct();
|
||||
unset($objFactory);
|
||||
$query = [ DB_TOKEN => [ OPERAND_NULL => [ OPERATOR_EQ => [ $guid ]]]];
|
||||
$request = [ STRING_QUERY_DATA => $query ];
|
||||
$objTest->_fetchRecords($request);
|
||||
if (!$objTest->status) {
|
||||
var_export($objTest->eventMessages);
|
||||
echo $eos;
|
||||
exit;
|
||||
}
|
||||
var_export($objTest->getData());
|
||||
break;
|
||||
case OP_AUDIT_RESTORE :
|
||||
$query = null;
|
||||
$errors = [];
|
||||
$retData = [];
|
||||
|
||||
// pre-determined DB_TOKEN of targeted audit record
|
||||
$queryData = [ STRING_KEY => "9E4CC946-BA7D-F329-AAA4-2471DB0AA829" ];
|
||||
$meta[META_USER_INFO] = basename(__FILE__);
|
||||
$meta[JOURNAL_HISTORY_RESTORED_REASON] = 'testing journal recovery';
|
||||
$meta[META_TEMPLATE] = TEMPLATE_CLASS_AUDIT;
|
||||
|
||||
// instantiate the audit record
|
||||
$objFactory = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, $queryData[STRING_KEY], $errors);
|
||||
if (!$objFactory->status) {
|
||||
echo ERROR_FACTORY_LOAD_BROKER . TEMPLATE_CLASS_AUDIT . $eos;
|
||||
var_export($objFactory->eventMessages);
|
||||
exit;
|
||||
}
|
||||
$objAudit = $objFactory->widget;
|
||||
if (is_object($objFactory)) $objFactory->__destruct();
|
||||
unset($objFactory);
|
||||
|
||||
// launch the audit process
|
||||
$startTime = gasStatic::doingTime();
|
||||
$rc = $objAudit->restoreAuditRecord($retData);
|
||||
$totalTime = gasStatic::doingTime($startTime);
|
||||
if ($rc === true) echo 'Audit record recovered in: ' . (string) $totalTime . ' seconds' . $eos;
|
||||
elseif (is_null($rc)) echo 'Audit method returned null' . $eos;
|
||||
else echo 'Audit request failed';
|
||||
var_export($objAudit->eventMessages);
|
||||
break;
|
||||
case OP_UPDATE :
|
||||
$query = [ CM_TST_FIELD_TEST_STATUS => [ OPERAND_NULL => [ OPERATOR_EQ => [ STATUS_ACTIVE ]]]];
|
||||
$update = [ CM_TST_FIELD_TEST_INT => 1319, CM_TST_FIELD_TEST_BOOL => true, CM_TST_FIELD_TEST_STRING => $jayne ];
|
||||
$orderBy = [ CM_TST_FIELD_TEST_CDATE => STRING_SORT_DESC ];
|
||||
$data = [ STRING_QUERY_DATA => $query, STRING_UPDATE_DATA => $update, STRING_ORDER_BY_DATA => $orderBy ];
|
||||
$metaCopy = $meta;
|
||||
// limit the update to five records
|
||||
$metaCopy[META_LIMIT] = 5;
|
||||
$request = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_UPDATE,
|
||||
BROKER_DATA => $data,
|
||||
BROKER_META_DATA => $metaCopy
|
||||
];
|
||||
if (!validateMetaData($request, $errors)) {
|
||||
var_export($errors);
|
||||
exit;
|
||||
}
|
||||
$objTest->_updateRecord($request[BROKER_DATA]);
|
||||
$queryResults = (!gasCache::mapOutboundPayload($objTest, $errors)) ? $objTest->getData() : $objTest->getCK();
|
||||
var_export($queryResults);
|
||||
break;
|
||||
case OP_CALL_SP :
|
||||
$query = [ STRING_PROCEDURE_NAME => 'testProc1', STRING_PARAM_LIST => [ 70 ]];
|
||||
$query = [ STRING_PROCEDURE_NAME => 'testProc0', STRING_PARAM_LIST => null ];
|
||||
$query = [ STRING_PROCEDURE_NAME => 'testProc2', STRING_PARAM_LIST => [12]];
|
||||
$objTest->execSP($query);
|
||||
break;
|
||||
case OP_UPDATE_DELETE :
|
||||
$recordToken = '9A49D075-70B3-8087-407A-ADE7EBB06246';
|
||||
$query = [ DB_TOKEN => [ OPERAND_NULL => [ OPERATOR_EQ => [ $recordToken ]]]];
|
||||
$update = [ DB_STATUS => STATUS_DELETED ];
|
||||
$objTest->addMeta(META_AUDIT_EVENT, 1); // simulate call to AdminIn broker audit restore event
|
||||
$objTest->_updateRecord([ STRING_QUERY_DATA => $query, STRING_UPDATE_DATA => $update]);
|
||||
var_export($objTest->eventMessages);
|
||||
break;
|
||||
case OP_UPDATE_MANY :
|
||||
$newMeta = $meta;
|
||||
$newMeta[META_LIMIT] = 3;
|
||||
// $query = [ CM_TST_FIELD_TEST_STATUS => [ OPERAND_NULL => [ OPERATOR_EQ => [ STATUS_ACTIVE ]]]];
|
||||
$query = [ CM_TST_FIELD_TEST_STRING => [ OPERAND_NULL => [ OPERATOR_DNE => [ $jayne ]]]];
|
||||
$update = [CM_TST_FIELD_TEST_STRING => $jayne, CM_TST_FIELD_TEST_INT => 12345 ];
|
||||
$orderBy = [ CM_TST_FIELD_TEST_CDATE => STRING_SORT_DESC ];
|
||||
$request = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_UPDATE,
|
||||
BROKER_DATA => [
|
||||
STRING_QUERY_DATA => $query,
|
||||
STRING_UPDATE_DATA => $update,
|
||||
STRING_SORT_DATA => $orderBy
|
||||
],
|
||||
BROKER_META_DATA => $newMeta
|
||||
];
|
||||
if (!validateMetaData($request, $errors)) {
|
||||
var_export($errors);
|
||||
exit;
|
||||
}
|
||||
|
||||
// $bc = new gacBrokerClient(BROKER_QUEUE_W, basename(__FILE__) . AT . __LINE__);
|
||||
// if (!$bc->status) exit(ERROR_BROKER_CLIENT_DECLARE . BROKER_QUEUE_W);
|
||||
// $payload = gzcompress(json_encode($request));
|
||||
// $response = json_decode(gzuncompress($bc->call($payload)), true);
|
||||
// var_export($response);
|
||||
|
||||
$objTest->replaceMeta($newMeta);
|
||||
$objTest->_updateRecord($request[BROKER_DATA]);
|
||||
$queryResults = (!gasCache::mapOutboundPayload($objTest, $errors)) ? $objTest->getData() : $objTest->getCK();
|
||||
var_export($queryResults);
|
||||
break;
|
||||
}
|
||||
if (!empty($objTest->eventMessages)) var_export($objTest->eventMessages);
|
||||
if (!$objTest->status) {
|
||||
echo 'test failed... ' . PHP_EOL;
|
||||
if (!empty($objTest->eventMessages))
|
||||
foreach ($objTest->eventMessages as $msg) consoleLog($res, CON_ERROR, $msg);
|
||||
else
|
||||
echo 'no messages in error stack...';
|
||||
} else {
|
||||
echo 'Test successfully completed' . $eos;
|
||||
}
|
||||
31
stubs/testPasswords.php
Normal file
31
stubs/testPasswords.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
|
||||
$x = md5('einstein'); // this will hash to the same value every time
|
||||
echo 'md5: ' . $x . PHP_EOL;
|
||||
$y = password_hash($x, PASSWORD_ARGON2I); // this hashes differently every time b/c the salt is auto generated
|
||||
echo PHP_EOL . 'hash: ' . PHP_EOL;
|
||||
echo $y . PHP_EOL;
|
||||
if (password_verify($x, $y))
|
||||
echo 'passwords match' . PHP_EOL;
|
||||
else
|
||||
echo 'Passwords do not match' . PHP_EOL;
|
||||
|
||||
$email = 'captain@serenity.space';
|
||||
$token = '10F00599-F8DA-ADF3-7033-7A1CACF2879D';
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_USERS,
|
||||
META_CLIENT => CLIENT_API_USER,
|
||||
META_DO_CACHE => 0,
|
||||
CLIENT_AUTH_TOKEN => '136EA67A-B1E2-0A4B-2BD8-EE34D39DFDE1',
|
||||
META_EVENT_GUID => guid(),
|
||||
|
||||
];
|
||||
$obj = new gacUsers($meta);
|
||||
if (!$obj->status)
|
||||
exit(ERROR_TEMPLATE_INSTANTIATE . TEMPLATE_CLASS_USERS);
|
||||
|
||||
$results = $obj->hashCheck($email, $x);
|
||||
echo PHP_EOL;
|
||||
var_export($results);
|
||||
echo PHP_EOL;
|
||||
69
stubs/testReferences.php
Normal file
69
stubs/testReferences.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/*
|
||||
* this stub tests the ability to reference different class objects, via a generic class member, and still have the
|
||||
* IDE access the member functions and variables of the assigned class without generating warnings or errors.
|
||||
*
|
||||
* 01-07-20 mks original coding
|
||||
*/
|
||||
|
||||
class bar
|
||||
{
|
||||
public int $y;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->y = 0;
|
||||
}
|
||||
|
||||
public function changeY(int $newValue): bool
|
||||
{
|
||||
if ($newValue == $this->y) return false;
|
||||
$this->y = $newValue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class foo
|
||||
{
|
||||
public int $x;
|
||||
public object $copy;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->x = 1;
|
||||
$this->copy = new stdClass();
|
||||
}
|
||||
|
||||
public function changeX(int $newValue = 1): bool
|
||||
{
|
||||
if ($newValue == $this->x) return false;
|
||||
$this->x = $newValue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$original = new foo();
|
||||
|
||||
echo 'Value of original->x: ' . $original->x . PHP_EOL;
|
||||
echo 'Value of original->x was ' . ($original->changeX(10)) ? '' : 'not ';
|
||||
echo 'changed.' . PHP_EOL;
|
||||
|
||||
// assign the reference
|
||||
$original->copy =& $original;
|
||||
|
||||
echo 'Value of copy->x ' . $original->copy->changeX(10) ? '' : 'not ';
|
||||
echo 'changed.' . PHP_EOL;
|
||||
|
||||
echo 'value of original->copy->x: ' . $original->copy->x . PHP_EOL;
|
||||
|
||||
// reassign the object $original->copy to the class object $argle
|
||||
$objectTwo = new bar();
|
||||
$original->copy =& $objectTwo;
|
||||
// note that even though $original->copy is decl as type object, we can still assign another object, of type argle
|
||||
// to the member AND access that member's functions without generating a warning!
|
||||
if ($original->copy->changeY(10))
|
||||
echo 'original->copy value changed!' . PHP_EOL;
|
||||
else
|
||||
echo 'original->copy unchanged' . PHP_EOL;
|
||||
|
||||
echo 'value of original->copy->y: ' . $original->copy->y . PHP_EOL;
|
||||
70
stubs/testRemoteFetch.php
Normal file
70
stubs/testRemoteFetch.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* CORE-1000 -- stubby little script to test-out namaste's remote fetch ability.
|
||||
*
|
||||
* @author mike@givingassistant.org
|
||||
* @version 1.0
|
||||
*
|
||||
* HISTORY:
|
||||
* ========
|
||||
* 06-07-18 mks CORE-1000: initial coding
|
||||
*
|
||||
*/
|
||||
|
||||
// load the namaste environment
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
const OBJECT = 1;
|
||||
const BROKER = 2;
|
||||
|
||||
$res = '_TRF: '; // test remote fetch
|
||||
|
||||
// if processing is OBJECT, we can use the debugger
|
||||
// if processing is BROKER, event is passed to migration broker
|
||||
$processing = OBJECT;
|
||||
|
||||
// set up the data payloads
|
||||
$meta = [
|
||||
META_CLIENT => CLIENT_SYSTEM, // back-door the meta-data checks
|
||||
// this is a meta-record so this request will go to the admin service
|
||||
META_TEMPLATE => TEMPLATE_CLASS_WAREHOUSE, // choose a template that's not local to appServer
|
||||
// this template is for a warehouse record so the request will go to segundo service
|
||||
META_TEMPLATE => TEMPLATE_CLASS_WHC1_PROD_REG,
|
||||
META_CLIENT_IP => STRING_SESSION_HOME, // required
|
||||
META_EVENT_GUID => guid() // simulate a broker event by generating the event guid
|
||||
];
|
||||
|
||||
// warehouse meta data (admin)
|
||||
$data = [
|
||||
STRING_QUERY_DATA => [ DB_TOKEN => [OPERAND_NULL => [OPERATOR_EQ => ['96811337-85F1-A274-8557-F8312B757D74']]]]
|
||||
];
|
||||
|
||||
// warehouse actual data (segundo)
|
||||
$data = [
|
||||
STRING_QUERY_DATA => [ DB_WH_TOKEN => [OPERAND_NULL => [OPERATOR_EQ => ['8C87E8E9-33E4-42A6-59FA-741711453DFF']]]]
|
||||
];
|
||||
|
||||
// This request event is only available in the namaste (appServer) read broker. However, the data (template) defines
|
||||
// the segundo service...which has an event called BROKER_REQUEST_REMOTE_FETCH. This event will be called, on behalf
|
||||
// of the client, by the read-broker...
|
||||
$request = BROKER_REQUEST_FETCH;
|
||||
|
||||
$request = [
|
||||
BROKER_REQUEST => $request,
|
||||
BROKER_DATA => $data,
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
$payload = gzcompress(json_encode($request));
|
||||
|
||||
$brokerClient = new gacBrokerClient(BROKER_QUEUE_R, __METHOD__ . AT . __LINE__);
|
||||
if (!$brokerClient->status) {
|
||||
consoleLog($res, CON_ERROR, ERROR_BROKER_CLIENT_DECLARE . BROKER_QUEUE_R);
|
||||
|
||||
} else {
|
||||
$response = $brokerClient->call($payload);
|
||||
$response = json_decode(gzuncompress($response), true);
|
||||
|
||||
var_export($response);
|
||||
}
|
||||
if (is_object($brokerClient)) $brokerClient->__destruct();
|
||||
unset($brokerClient);
|
||||
echo $eos . 'Program ends...' . $eos;
|
||||
18
stubs/testSessionExpire.php
Normal file
18
stubs/testSessionExpire.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
$errors = [];
|
||||
$tokenGUID = 'D8637D12-B514-2916-D01C-05E416755451';
|
||||
$request = [ STRING_GUID_KEY => $tokenGUID, STRING_TOK_TYPE => STRING_TOK_TYPE_SES];
|
||||
$meta = [ META_TEMPLATE => TEMPLATE_CLASS_SESSIONS, META_CLIENT => CLIENT_SYSTEM];
|
||||
/** @var gacMongoDB $obj */
|
||||
$obj = grabWidget($meta, $tokenGUID,$errors);
|
||||
if (is_null($obj)) {
|
||||
var_export($errors);
|
||||
echo PHP_EOL;
|
||||
exit('failed to create widget' . $eos);
|
||||
}
|
||||
/** @var gatSessions $template */
|
||||
$template = $obj->template;
|
||||
$payload = $template->buildExpireSessionPayload($request, $errors);
|
||||
$obj->_updateRecord($payload);
|
||||
echo 'Program ' .((!$obj->status) ? 'failed' : 'succeeded') . $eos;
|
||||
41
stubs/testSingleton.php
Normal file
41
stubs/testSingleton.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* point of this stub is to show that explicit return values have no impact in static singleton class instantiation
|
||||
*/
|
||||
class foo {
|
||||
private $bar = 0;
|
||||
private static $instance;
|
||||
|
||||
private function __construct($_which)
|
||||
{
|
||||
static::$instance = null;
|
||||
switch ($_which) {
|
||||
case 1 :
|
||||
return true;
|
||||
break;
|
||||
case 2 :
|
||||
return false;
|
||||
break;
|
||||
default :
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getInstance($_w)
|
||||
{
|
||||
if (static::$instance === null) {
|
||||
$c = __CLASS__;
|
||||
static::$instance = new $c($_w);
|
||||
}
|
||||
return(static::$instance);
|
||||
}
|
||||
}
|
||||
|
||||
$bar = foo::getInstance(1);
|
||||
var_export($bar);
|
||||
$bar = foo::getInstance(2);
|
||||
var_export($bar);
|
||||
$bar = foo::getInstance(0);
|
||||
var_export($bar);
|
||||
|
||||
24
stubs/testSystemEvents.php
Normal file
24
stubs/testSystemEvents.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
$errors = [];
|
||||
$logger = new gacErrorLogger();
|
||||
if (!$logger->status) exit(ERROR_TEMPLATE_INSTANTIATE . TEMPLATE_CLASS_LOGS);
|
||||
$groot = guid();
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_USERS,
|
||||
META_CLIENT => CLIENT_API_USER,
|
||||
META_DO_CACHE => 0,
|
||||
META_SESSION_MISC => 'system test'
|
||||
];
|
||||
|
||||
$eventData = [
|
||||
SYSTEM_EVENT_NAME => EVENT_NAME_SYSTEM_TEST,
|
||||
SYSTEM_EVENT_STATUS => STATUS_ACTIVE,
|
||||
SYSTEM_EVENT_TYPE => EVENT_TYPE_TEST,
|
||||
SYSTEM_EVENT_FK_SESSION_GUID => guid(),
|
||||
SYSTEM_EVENT_CODE_LOC => basename(__FILE__) . AT . __LINE__,
|
||||
SYSTEM_EVENT_META_DATA => $meta,
|
||||
SYSTEM_EVENT_NOTES => 'This is a test.'
|
||||
];
|
||||
@postSystemEvent($eventData, $groot, $logger);
|
||||
|
||||
15
stubs/testUsers.php
Normal file
15
stubs/testUsers.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
// load the namaste environment
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
$meta = [
|
||||
META_TEMPLATE => TEMPLATE_CLASS_USERS,
|
||||
META_CLIENT => CLIENT_API_USER,
|
||||
META_EVENT_GUID => guid(),
|
||||
META_DO_CACHE => false,
|
||||
META_TLTI => STRING_CLASS_GAT
|
||||
];
|
||||
$errors = [];
|
||||
$obj = new gacFactory($meta, FACTORY_EVENT_NEW_CLASS, '', $errors);
|
||||
$widget = $obj->widget;
|
||||
$obj->__destruct();;
|
||||
unset($obj);
|
||||
78
stubs/testWH.php
Normal file
78
stubs/testWH.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* testWH.php -- warehousing test script
|
||||
*
|
||||
*/
|
||||
|
||||
// load the namaste environment
|
||||
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
||||
const OBJECT = 1;
|
||||
const BROKER = 2;
|
||||
|
||||
// if processing is OBJECT, we can use the debugger
|
||||
// if processing is BROKER, event is passed to migration broker
|
||||
$processing = OBJECT;
|
||||
|
||||
// set up the data payloads
|
||||
$meta = [
|
||||
META_CLIENT => CLIENT_SYSTEM,
|
||||
// META_TEMPLATE => TEMPLATE_CLASS_PRODUCT_REG, // mongoDB template
|
||||
META_TEMPLATE => TEMPLATE_CLASS_PROD_REGS, // mySQL template
|
||||
META_CLIENT_IP => STRING_SESSION_HOME,
|
||||
META_EVENT_GUID => guid() // simulate a broker event by generating the event guid
|
||||
];
|
||||
|
||||
// data payload for an internal warehousing request
|
||||
$data = [
|
||||
MWH_TEST_MODE => 1,
|
||||
WH_TYPE => WH_TYPE_COOL,
|
||||
WH_AUTOMATED => false,
|
||||
WH_FILTER_VALUES => [ '1970-01-01', '2017-02-17' ] // (required) should return 11 records
|
||||
];
|
||||
|
||||
// data payload for an external source request
|
||||
$remoteData = [
|
||||
MWH_TEST_MODE => 1,
|
||||
WH_TYPE => WH_TYPE_COOL,
|
||||
WH_AUTOMATED => false,
|
||||
WH_SOURCE_IS_REMOTE => true,
|
||||
WH_REMOTE_TABLE => 'product_registrations',
|
||||
WH_REMOTE_CDATE_FIELD => 'kinsert_date',
|
||||
WH_FILTER_VALUES => [ '1970-01-01', '2017-02-17' ] // (required) should return 11 records
|
||||
];
|
||||
|
||||
if ($processing == OBJECT) {
|
||||
// $objTest = new gacMigrations($data, $meta, EVENT_WAREHOUSE);
|
||||
$objTest = new gacMigrations($remoteData, $meta, EVENT_WAREHOUSE);
|
||||
|
||||
if (!$objTest->status) {
|
||||
echo ERROR_TEMPLATE_INSTANTIATE . TEMPLATE_CLASS_MIGRATIONS . $eos;
|
||||
var_export($objTest->errorStack);
|
||||
exit(1);
|
||||
}
|
||||
// this is what the broker calls:
|
||||
if (!$objTest->whData()) {
|
||||
var_export($objTest->errorStack);
|
||||
exit(1);
|
||||
}
|
||||
echo 'program successfully completed execution' . $eos;
|
||||
echo $objTest->migrationReport;
|
||||
echo $eos . $eos;
|
||||
} elseif ($processing == BROKER) {
|
||||
if (isset($meta[META_EVENT_GUID])) unset($meta[META_EVENT_GUID]);
|
||||
$bc = new gacBrokerClient(BROKER_QUEUE_W, __METHOD__ . AT . __LINE__);
|
||||
if (!$bc->status) {
|
||||
$error = ERROR_BROKER_CLIENT_DECLARE . BROKER_QUEUE_W;
|
||||
echo $error . $eos;
|
||||
exit(1);
|
||||
}
|
||||
$request = [
|
||||
BROKER_REQUEST => BROKER_REQUEST_WAREHOUSE,
|
||||
BROKER_DATA => $remoteData,
|
||||
BROKER_META_DATA => $meta
|
||||
];
|
||||
$response = json_decode(gzuncompress($bc->call(gzcompress(json_encode($request)))), true);
|
||||
var_export($response);
|
||||
} else {
|
||||
echo 'processing type not supported...' . $eos . $eos;
|
||||
}
|
||||
Reference in New Issue
Block a user