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:
655
classes/templates/gatProdRegistrations.class.inc
Normal file
655
classes/templates/gatProdRegistrations.class.inc
Normal file
@@ -0,0 +1,655 @@
|
||||
<?php
|
||||
/**
|
||||
* gatProdRegistrations.class -- Namaste mySQL Data Template
|
||||
*
|
||||
* This is the template file for the Namaste mySQL version of product-registration. This template was created for the
|
||||
* purpose of testing mysql->mysql data migration.
|
||||
*
|
||||
* There is another prod-reg template: gatProductRegistrations.class.inc -- which is a mongo data template.
|
||||
*
|
||||
* Once version 1.0.0 of Namaste is launched, please remember to deprecate either this, or the other, template class
|
||||
* so that there is no potential for confusion.
|
||||
*
|
||||
*
|
||||
* @author mike@givingassistant.org
|
||||
* @version 1.0
|
||||
*
|
||||
*
|
||||
* HISTORY:
|
||||
* ========
|
||||
* 03-23-18 mks CORE-852: original coding
|
||||
* 04-18-18 mks _INF-188: warehousing section added
|
||||
* 06-12-18 mks CORE-1043: updated PDO objects to add SQL statements for table create, update
|
||||
* 01-13-20 mks DB-150: PHP7.4 class member type-casting
|
||||
* 06-01-20 mks ECI-108: support for auth token
|
||||
*
|
||||
*/
|
||||
|
||||
class gatProdRegistrations
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// CLASS PROPERTIES...
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public int $version = 1; // template version: not the same as the release version
|
||||
public string $service = CONFIG_DATABASE_SERVICE_APPSERVER; // defines the mongo server destination
|
||||
public string $schema = TEMPLATE_DB_PDO; // defines the storage schema for the class
|
||||
public string $templateClass = TEMPLATE_CLASS_PROD_REGS; // defines the clear-text template class name
|
||||
public string $collection = COLLECTION_PDO_PROD_REGS; // sets the collection (table) name
|
||||
public ?string $whTemplate = TEMPLATE_CLASS_WHC1_PROD_REG; // name of the warehouse template (not collection)
|
||||
public string $extension = COLLECTION_PDO_PROD_REGS_EXT; // sets the extension for the collection
|
||||
public bool $closedClass = true; // set to false to allow partner instantiations
|
||||
public bool $setCache = false; // set to true to cache class data
|
||||
public bool $setDeletes = false; // set to true to allow HARD deletes (otherwise: SOFT)
|
||||
public int $setAuditing = AUDIT_NOT_ENABLED; // set to AUDIT_value constant
|
||||
public bool $setJournaling = false; // set to true to allow journaling
|
||||
public bool $setUpdates = true; // set to true to allow record updates
|
||||
public bool $setHistory = false; // set 2 true to enable detailed record history tracking
|
||||
public string $setDefaultStatus = STATUS_ACTIVE; // set the default status for each record
|
||||
public string $setSearchStatus = STATUS_ACTIVE; // set the default search status
|
||||
public bool $setLocking = false; // set to true to enable record locking for collection
|
||||
public bool $setTimers = true; // set to true to enable collection query timers
|
||||
public string $setPKey = DB_TOKEN; // sets the primary key for the collection
|
||||
public bool $setTokens = true; // set to true: adds the idToken field functionality
|
||||
public bool $selfDestruct = false; // set to false if class contains methods or migration
|
||||
public int $cacheTimer = 0; // number of seconds a tuple will remain in-cache
|
||||
public bool $isGA = false; // set to true is this class is a Namaste internal class
|
||||
public ?string $authToken = null; // if this data class is registered to a partner, you will
|
||||
// need to initialize this member in the constructor (hard-coded)
|
||||
|
||||
// fields: a key-value paired array, defines the field name and the data type for each field. Prior to insertion,
|
||||
// all data is validated for type and membership. Data that does not satisfy these requirements is
|
||||
// silently dropped prior to insertion.
|
||||
//
|
||||
// Note that for PDO-type tables, the data type is more ... homogeneous... e.g.: data types define the data
|
||||
// type only. It does not define the actual column type in-use. For example, there is no distinction made
|
||||
// between a tinyInt, Int, or BigInt. As far as the framework is concerned, they're all just integers.
|
||||
//
|
||||
public array $fields = [
|
||||
PDO_ID => DATA_TYPE_INTEGER, // sorting by the id is just like sorting by createdDate
|
||||
PRG_TYPE => DATA_TYPE_STRING,
|
||||
PRG_IID => DATA_TYPE_STRING,
|
||||
PRG_EAV => DATA_TYPE_STRING,
|
||||
PRG_PLATFORM => DATA_TYPE_STRING,
|
||||
PRG_BROWSER => DATA_TYPE_STRING,
|
||||
PRG_MAJOR_VERSION => DATA_TYPE_INTEGER,
|
||||
PRG_MINOR_VERSION => DATA_TYPE_INTEGER,
|
||||
PRG_IS_MOBILE => DATA_TYPE_INTEGER,
|
||||
PRG_IS_TABLET => DATA_TYPE_INTEGER,
|
||||
PRG_FIRST_SEEN => DATA_TYPE_STRING,
|
||||
PRG_LAST_SEEN => DATA_TYPE_STRING,
|
||||
DB_TOKEN => DATA_TYPE_STRING, // unique key (string) exposed externally and is REQUIRED,
|
||||
DB_EVENT_GUID => DATA_TYPE_STRING, // track-back identifier for broker/events
|
||||
DB_CREATED => DATA_TYPE_STRING, // dateTime type
|
||||
DB_STATUS => DATA_TYPE_STRING, // record status
|
||||
DB_ACCESSED => DATA_TYPE_STRING // dateTime type
|
||||
];
|
||||
|
||||
// protected fields are fields that a client is unable to modify or delete. If a client submits a query that
|
||||
// updates these fields, the query will be rejected (worst case) or the directive to update/delete the field
|
||||
// will be silently dropped (best case). In either way, updating or removing this fields cannot be accomplished.
|
||||
//
|
||||
// Minimally, this array should contain the following fields:
|
||||
// -- DB_TOKEN, DB_EVENT_GUID, DB_CREATED, DB_ACCESSED
|
||||
// -- the ID field (either PDO_ID or MONGO_ID)
|
||||
// -- DB_WH_CREATED, DB_WH_EVENT_GUID, DB_WH_TOKEN
|
||||
//
|
||||
public ?array $protectedFields = [
|
||||
DB_TOKEN, DB_EVENT_GUID, DB_CREATED, DB_ACCESSED, PDO_ID
|
||||
];
|
||||
|
||||
// all fields that appear in any of the index declarations must appear in this list as this is the property
|
||||
// that's used in the framework as an authoritative check to qualify discriminant fields as indexes.
|
||||
//
|
||||
// indexes are always declared with the template column name and not the cache-map column name
|
||||
//
|
||||
// warehouse indexes are limited to the original record's created date and the three WH fields only
|
||||
//
|
||||
// NOTE: if you're going to declare a single column as a property, then do NOT also declare it as a single index!
|
||||
//
|
||||
public array $indexFields = [
|
||||
PDO_ID => 1,
|
||||
PRG_EAV => 1,
|
||||
PRG_IID => 1,
|
||||
PRG_TYPE => 1,
|
||||
DB_CREATED => 1,
|
||||
DB_STATUS => 1, // status should only be indexed if soft-deletes are enabled (just saying)
|
||||
DB_EVENT_GUID => 1, // event guid should always be indexed
|
||||
DB_TOKEN => 1
|
||||
];
|
||||
|
||||
|
||||
// all index names that are explicitly declared in the indexes below must also appear in this array. If there are
|
||||
// no pre-defined index names, then this field should be set to null.
|
||||
//
|
||||
// Note that if you're allowing mysql to generate the index names for you, and if you use a partial index (below)
|
||||
// that references that randomly-generated index name, and that name does not appear in this list, then you will
|
||||
// fail to load that template at run time, every time.
|
||||
//
|
||||
// You have been warned.
|
||||
//
|
||||
public ?array $indexNameList = [ 'cIdx1Test'];
|
||||
|
||||
|
||||
// the primary key index is declared in the class properties section as $setPKey
|
||||
|
||||
// unique indexes are to be used a values stored in these columns have to be unique to the table. Note that
|
||||
// null values are permissible in unique-index columns. Do not declare MONGO_ID here, regardless of how badly
|
||||
// you may want to.
|
||||
public ?array $uniqueIndexes = [ DB_TOKEN => 1 ];
|
||||
|
||||
// single field index declarations -- since you can have a field in more than one index (index, multi)
|
||||
// the format for the single-field index declaration is a simple indexed array.
|
||||
public ?array $singleFields = [
|
||||
PRG_EAV, PRG_IID, PRG_TYPE, DB_EVENT_GUID
|
||||
];
|
||||
|
||||
// multiKey indexes are indexes on fields that are arrays (not the same as sub-collections) which indexes the
|
||||
// content stored in the array based on the column names.
|
||||
//
|
||||
// mongo, as of 3.4, automatically creates a multi-key index on any field declared as a (sic) index that's
|
||||
// an array. Meaning: we don't need to explicitly create a multi-key index on an array field if that field
|
||||
// is declared as a single-key, compound, or unique index.
|
||||
//
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// NOTES: if you implicitly declare a multi-key index by using the column as a compound-index field, then you
|
||||
// may, at MOST, have one array within the compound index.
|
||||
//
|
||||
// You may NOT declare a multi-key index as a shard key.
|
||||
//
|
||||
// Hashed keys may NOT be multi-key.
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// In other words, if you want to apply an index to ALL of the array element then declare the column as singleField,
|
||||
// or compound, or unique. This will have the multi-key index automagically applied by mongoDB.
|
||||
//
|
||||
// If you want to index a subset of the array, then declare the fields to be indexed by using dot notation:
|
||||
//
|
||||
// [ 'someIndex' => [ arrayColumnName.subField1 => 1, arrayColumnName.subField3 => -1 ... ] ]
|
||||
//
|
||||
// And this will apply the multi-key index property to subField1 and subField3 only.
|
||||
//
|
||||
// multiKey indexes are referenced by an index name in order to remove ambiguity when parsing index-properties
|
||||
// against this and other indexes that may have the same field name. In other words, index-properties that will
|
||||
// be applied to a multiKey index must reference the multiKey index by the index (and not the column) name.
|
||||
//
|
||||
// example:
|
||||
// [ 'mIdx1Test' => [ ARRAY_FIELD_NAME => <1|-1>, ... ]]
|
||||
//
|
||||
public ?array $compoundIndexes = [
|
||||
'cIdx1Test' => [ DB_CREATED, DB_STATUS ]
|
||||
];
|
||||
|
||||
|
||||
// NOTE: foreign-key indexes are not explicitly enumerated in a template -- that relationship is defined in the
|
||||
// schema for the table. Foreign-key indexes appear implicitly in the indexing declarations above.
|
||||
|
||||
|
||||
// cache maps are requires for namaste service classes. Even if caching is disabled for a class, a cache map is
|
||||
// still required for the class. For PDO classes, the PDO_ID is never included in the mapping, nor is MONGO_ID.
|
||||
public ?array $cacheMap = [
|
||||
PRG_TYPE => CM_PRG_TYPE,
|
||||
PRG_IID => CM_PRG_IID,
|
||||
PRG_EAV => CM_PRG_EAV,
|
||||
PRG_PLATFORM => CM_PRG_PLATFORM,
|
||||
PRG_BROWSER => CM_PRG_BROWSER,
|
||||
PRG_MAJOR_VERSION => CM_PRG_MAJ_VER,
|
||||
PRG_MINOR_VERSION => CM_PRG_MIN_VER,
|
||||
PRG_IS_MOBILE => CM_PRG_IS_MOBILE,
|
||||
PRG_IS_TABLET => CM_PRG_IS_TABLET,
|
||||
PRG_FIRST_SEEN => CM_PRG_FIRST_SEEN,
|
||||
PRG_LAST_SEEN => CM_PRG_LAST_SEEN,
|
||||
DB_TOKEN => CM_TST_TOKEN,
|
||||
DB_STATUS => CM_TST_FIELD_TEST_STATUS,
|
||||
DB_EVENT_GUID => CM_TST_EVENT_GUID,
|
||||
DB_CREATED => CM_TST_FIELD_TEST_CDATE,
|
||||
DB_ACCESSED => CM_TST_FIELD_TEST_ADATE
|
||||
];
|
||||
|
||||
/*
|
||||
* if there is no cache-mapping supported for the class, and you want to limit the fields returned,
|
||||
* then those fields are listed here as an associative array.
|
||||
*
|
||||
* NOTE: You can have caching disabled for the class and still have a cache-map -- this controls the labels
|
||||
* assigned to the returned data column names exposed to the client. Schema should never be exposed.
|
||||
*
|
||||
* NOTE: if you do not support caching for the class and this class is one that is returned to a client,
|
||||
* (some classes are limited to internal use only, like logging), then you should (at a minimum)
|
||||
* exclude the primary key field (integer).
|
||||
*
|
||||
*
|
||||
* This array is an associative array -- the key is the native column name and the value doesn't matter. The
|
||||
* important thing is that the keys are the column names that you want to return back to the client.
|
||||
*
|
||||
* If $exposedFields is to be undefined for the class, then assign it a null.
|
||||
*
|
||||
*/
|
||||
public ?array $exposedFields = [
|
||||
PRG_TYPE => 1,
|
||||
PRG_IID => 1,
|
||||
PRG_EAV => 1,
|
||||
PRG_PLATFORM => 1,
|
||||
PRG_BROWSER => 1,
|
||||
PRG_MAJOR_VERSION => 1,
|
||||
PRG_MINOR_VERSION => 1,
|
||||
PRG_IS_MOBILE => 1,
|
||||
PRG_IS_TABLET => 1,
|
||||
PRG_FIRST_SEEN => 1,
|
||||
PRG_LAST_SEEN => 1,
|
||||
DB_TOKEN => 1,
|
||||
DB_CREATED => 1, // epoch time
|
||||
DB_STATUS => 1, // record status
|
||||
DB_ACCESSED => 1 // epoch time
|
||||
];
|
||||
|
||||
// in PDO-land, binary fields are your basic data blobs. All binary fields require special handling and so
|
||||
// need to be enumerated here as an indexed array.
|
||||
public ?array $binFields = null;
|
||||
|
||||
|
||||
// DB SQL:
|
||||
// -------
|
||||
// PDO SQL is stored in the template and is keyed by the current namaste version (defined in the XML file) during
|
||||
// execution of the deployment script. Each version denotes a container of SQL commands that will be executed
|
||||
// for the targeted version.
|
||||
//
|
||||
// SQL is versioned in parallel with the Namaste (XML->application->id->version) version. Each PDO_SQL
|
||||
// sub-container has several fields - one of which has the version identifier. When the deployment script
|
||||
// executes, the release versions are compared and, if they're an exact match, the SQL is submitted for execution.
|
||||
//
|
||||
// The PDO_SQL container consists of these sub-containers:
|
||||
//
|
||||
// PDO_SQL_VERSION --> this is a float value in the form of x.y as namaste only supports versions as a major
|
||||
// and minor release number. (Patch releases are minor release increments.)
|
||||
// PDO_TABLE --> string value containing the full table name.
|
||||
// PDO_SQL_FC --> the FC means "first commit" -- when the table is first created, it will execute the
|
||||
// SQL in this block, if it exists, and if the version number for the sub-container
|
||||
// exactly matched the version number in the configuration XML.
|
||||
// PDO_SQL_UPDATE --> When the sub-container PDO_SQL_VERSION value exactly matches the XML release value,
|
||||
// then the ALTER-TABLE sql in this update block will be executed.
|
||||
// STRING_DROP_CODE_IDX --> The boilerplate code for dropping the indexes of the table.
|
||||
// STRING_DROP_CODE_DEV --> For version 1.0 only, this points to code to drop the entire table.
|
||||
//
|
||||
// Again, containers themselves are indexed arrays under the PDO_SQL tag. Within the container, data is stored
|
||||
// as an associative array with the keys enumerated above.
|
||||
//
|
||||
//
|
||||
// DB OBJECTS:
|
||||
// -----------
|
||||
// DB objects are: views, procedures, functions and events.
|
||||
// All such objects assigned to a class are declared in this array under the appropriate header.
|
||||
// This is a safety-feature that prevents a one class (table) from invoking another class object.
|
||||
// The name of the object is stored as an indexed-array under the appropriate header.
|
||||
//
|
||||
// The format for these structures is basically the same. Each DBO is stored in an associative array with the
|
||||
// key defining the name of the object. Within each object, there are embedded associative arrays that have the
|
||||
// name of the object as the key and the object definition (text) and the value:
|
||||
//
|
||||
// objectType => [ objectName => [ objectContent ], ... ]
|
||||
//
|
||||
// Each created object should also have the directive to remove it's predecessor using a DROP statement.
|
||||
//
|
||||
// todo -- unset these objects post-instantiation so that schema is not revealed
|
||||
//
|
||||
// VIEWS:
|
||||
// ------
|
||||
// Every namaste table will have at least one view which limits the data fetched from the table. At a minimum,
|
||||
// the id_{ext} field is filtered from the resulting data set via the view. Other fields can be withheld as well
|
||||
// but that is something that is individually set-up for each table.
|
||||
//
|
||||
// The basic view has the following syntax for declaring it's name:
|
||||
// view_basic_{tableName_ext}
|
||||
// All views start with the word "view" so as to self-identify the object, followed by the view type which,
|
||||
// optimally, you should try to limit to a single, descriptive word.
|
||||
//
|
||||
// Following this label, which points to a sub-array containing three elements:
|
||||
// STRING_VIEW ----------> this is the SQL code that defines the view as a single string value
|
||||
// STRING_TYPE_LIST -----> null or an array of types that corresponds to variable markers ('?') in the sql
|
||||
// STRING_DESCRIPTION' --> a string that describes the purpose of the view.
|
||||
//
|
||||
// At a minimum, every class definition should contain at-least a basic view as all queries that don't specify
|
||||
// a named view or other DBO, will default to the the basic view in the FROM clause of the generated SQL.
|
||||
//
|
||||
// PROCEDURES:
|
||||
// -----------
|
||||
// For stored procedures, which are entirely optional, the array definition contains the following elements:
|
||||
// STRING_PROCEDURE -------> the SQL code that defined the stored procedure as a single string value
|
||||
// STRING_DROP_CODE -------> the sql code that drops the procedure (required for procedures!)
|
||||
// STRING_TYPE_LIST -------> an associative array of associative arrays -- in the top level, the key is the name
|
||||
// of the parameter that points to a sub-array that contains the parameter direction
|
||||
// as the key, and the parameter type as the value. There should be an entry for each
|
||||
// parameter to be passed to the stored procedure/function.
|
||||
//
|
||||
// ------------------------------------------------------
|
||||
// | NOTE: IN params must precede INOUT and OUT params! |
|
||||
// ------------------------------------------------------
|
||||
//
|
||||
// STRING_SP_EVENT_TYPE ---> Assign one of the DB_EVENT constants to this field to indicate the type of
|
||||
// query the stored-procedure will execute.
|
||||
// NOTE: there is not a defined PDO::PARAM constant for type float: use string.
|
||||
// STRING_DESCRIPTION -----> clear-text definition of the procedure's purpose
|
||||
//
|
||||
// Note that all of these containers are required; empty containers should contain a null placeholder.
|
||||
//
|
||||
// When a stored procedure contains a join of two or more tables/views, the first table listed is considered
|
||||
// to be the "owning" table and the procedure will be declared in the class template for that table, but it will
|
||||
// not be duplicated in other template classes referenced in the join.
|
||||
//
|
||||
public ?array $dbObjects = [
|
||||
PDO_SQL => [
|
||||
[
|
||||
PDO_VERSION => 1.0,
|
||||
PDO_TABLE => 'gaProductRegistrations_prg',
|
||||
PDO_SQL_FC => "
|
||||
--
|
||||
-- Table structure for table `gaProductRegistrations_prg`
|
||||
--
|
||||
|
||||
CREATE TABLE `gaProductRegistrations_prg` (
|
||||
`id_prg` int(10) UNSIGNED NOT NULL,
|
||||
`type_prg` char(16) NOT NULL,
|
||||
`iid_prg` char(64) NOT NULL,
|
||||
`eav_prg` char(16) DEFAULT NULL,
|
||||
`platform_prg` char(32) DEFAULT NULL,
|
||||
`browser_prg` char(32) DEFAULT NULL,
|
||||
`majorVersion_prg` int(11) DEFAULT NULL,
|
||||
`minorVersion_prg` int(11) DEFAULT NULL,
|
||||
`isMobile_prg` tinyint(3) UNSIGNED DEFAULT NULL,
|
||||
`isTablet_prg` tinyint(3) UNSIGNED DEFAULT NULL,
|
||||
`firstSeen_prg` datetime DEFAULT NULL,
|
||||
`lastSeen_prg` datetime DEFAULT NULL,
|
||||
`token_prg` char(36) NOT NULL,
|
||||
`eventGUID_prg` char(36) DEFAULT NULL,
|
||||
`createdDate_prg` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`lastAccessedDate_prg` datetime DEFAULT NULL,
|
||||
`status_prg` varchar(25) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
",
|
||||
PDO_SQL_UPDATE => "
|
||||
--
|
||||
-- Indexes for table `gaProductRegistrations_prg`
|
||||
--
|
||||
ALTER TABLE `gaProductRegistrations_prg`
|
||||
ADD PRIMARY KEY (`id_prg`),
|
||||
ADD UNIQUE KEY `token_prg` (`token_prg`),
|
||||
ADD KEY `type_prg` (`type_prg`,`iid_prg`),
|
||||
ADD KEY `createdDate_prg` (`createdDate_prg`,`lastAccessedDate_prg`,`status_prg`),
|
||||
ADD KEY `iid_prg` (`iid_prg`,`eav_prg`),
|
||||
ADD KEY `eventGUID_prg` (`eventGUID_prg`);
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `gaProductRegistrations_prg`
|
||||
--
|
||||
ALTER TABLE `gaProductRegistrations_prg`
|
||||
MODIFY `id_prg` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
|
||||
",
|
||||
/*
|
||||
* example query return:
|
||||
* ---------------------
|
||||
* ALTER TABLE gaTest_tst DROP INDEX gaTest_tst_createdDate_tst_status_tst_index, DROP INDEX
|
||||
* gaTest_tst_lastAccessedDate_tst_index, DROP INDEX testInteger_tst, DROP INDEX
|
||||
* gaTest_tst_eventGuid_tst_index, DROP INDEX testDouble_tst, DROP INDEX testString_tst;
|
||||
*
|
||||
* NOTE:
|
||||
* -----
|
||||
* The sql comment code tag (--) will be removed during mysqlConfig's run time processing
|
||||
*/
|
||||
STRING_DROP_CODE_IDX => "--
|
||||
SELECT CONCAT('ALTER TABLE ', `Table`, ' DROP INDEX ', GROUP_CONCAT(`Index` SEPARATOR ', DROP INDEX '),';' )
|
||||
FROM (
|
||||
SELECT table_name AS `Table`, index_name AS `Index`
|
||||
FROM information_schema.statistics
|
||||
WHERE INDEX_NAME != 'PRIMARY'
|
||||
AND table_schema = 'XXXDROP_DB_NAMEXXX'
|
||||
AND table_name = 'XXXDROP_TABLE_NAMEXXX'
|
||||
GROUP BY `Table`, `Index`) AS tmp
|
||||
GROUP BY `Table`;
|
||||
",
|
||||
STRING_DROP_CODE_DEV => "DROP TABLE IF EXISTS gaProductRegistrations_prg;" // only executed if declared
|
||||
]
|
||||
],
|
||||
PDO_VIEWS => [
|
||||
'view_basic_gaProductRegistrations' => [
|
||||
STRING_VIEW =>
|
||||
"DROP VIEW IF EXISTS view_basic_gaProductRegistrations;
|
||||
CREATE VIEW view_basic_gaProductRegistrations_prg AS
|
||||
SELECT type_prg, iid_prg, eav_prg, platform_prg, browser_prg, majorVersion_prg, minorVersion_prg,
|
||||
isMobile_prg, isTablet_prg, firstSeen_prg, lastSeen_prg, eventGUID_prg, createdDate_prg,
|
||||
lastAccessedDate_prg, status_prg, token_prg
|
||||
FROM gaProductRegistrations_prg
|
||||
WHERE status_prg <> \"DELETE\";",
|
||||
STRING_TYPE_LIST => null,
|
||||
STRING_DESCRIPTION => 'basic query'
|
||||
],
|
||||
],
|
||||
PDO_PROCEDURES => [],
|
||||
PDO_FUNCTIONS => [],
|
||||
PDO_EVENTS => [],
|
||||
PDO_TRIGGERS => []
|
||||
];
|
||||
|
||||
|
||||
//=================================================================================================================
|
||||
// MIGRATION DECLARATIONS
|
||||
// ----------------------
|
||||
// Data in this section is used to handle migrations -- when we're pulling from legacy tables into the Namaste
|
||||
// framework. See online doc for more info.
|
||||
//=================================================================================================================
|
||||
|
||||
/**
|
||||
* The migration map is an associative array that maps the Namaste fields (keys) to the corresponding
|
||||
* (remote) legacy fields in the source table to be migrated to Namaste.
|
||||
*
|
||||
* For example, if we were migrating a mysql table in the legacy production database to Namaste::mongo, then
|
||||
* the keys of the migration map would be the Namaste::mongo->fieldNames and the values would be the mysql
|
||||
* column names in the legacy table.
|
||||
*
|
||||
* If there is a value which cannot be mapped to a key, then set it to null.
|
||||
*
|
||||
* Fields that will be dropped in the migration are not listed as values or as keys.
|
||||
*
|
||||
* This map will only exist in the template object and will never be imported into the class widget.
|
||||
*
|
||||
* This is a required field.
|
||||
*
|
||||
*/
|
||||
public ?array $migrationMap = [
|
||||
PDO_ID => null, // created on insert
|
||||
PRG_TYPE => 'type',
|
||||
PRG_IID => 'iid',
|
||||
PRG_EAV => 'eav',
|
||||
PRG_PLATFORM => 'platform',
|
||||
PRG_BROWSER => 'browser',
|
||||
PRG_MAJOR_VERSION => 'major_version',
|
||||
PRG_MINOR_VERSION => 'minor_version',
|
||||
PRG_IS_MOBILE => 'is_mobile',
|
||||
PRG_IS_TABLET => 'is_tablet',
|
||||
PRG_FIRST_SEEN => 'first_seen',
|
||||
PRG_LAST_SEEN => 'last_seen',
|
||||
DB_TOKEN => null, // created on insert
|
||||
DB_EVENT_GUID => null, // generated by broker event
|
||||
DB_CREATED => 'kinsert_date', // epoch time
|
||||
DB_STATUS => null, // record status
|
||||
DB_ACCESSED => 'kupdate_date' // epoch time
|
||||
];
|
||||
|
||||
/*
|
||||
* the migrationSortKey defines the SOURCE field by which the fetch query will be sorted. ALL sort fields are
|
||||
* in ASC order so all we need to list here is the name of the field -- which MUST BE IN THE SOURCE TABLE.
|
||||
*
|
||||
* Populating this field may require preliminary examination of the data - what we want is a field that has
|
||||
* zero NULL values.
|
||||
*
|
||||
* This is a required field.
|
||||
*
|
||||
*/
|
||||
public ?string $migrationSortKey = 'last_seen';
|
||||
|
||||
/*
|
||||
* The migrationStatusKey defines the status field/column in the source table -- if the user requires that
|
||||
* soft-deleted records not be migrated, then this field must be set. Otherwise, set the value to null.
|
||||
*
|
||||
* The format is in the form of a key-value paired array. The key specifies the name of the column and the value
|
||||
* specifies the "deleted" value that, if found, will cause that row from the SOURCE data to be omitted from the
|
||||
* DESTINATION table.
|
||||
*
|
||||
* e.g.: $migrationStatusKV = [ 'some_field' => 'deleted' ]
|
||||
*
|
||||
* Note that both the key and the value are case-sensitive!
|
||||
*
|
||||
* This is an optional field.
|
||||
*
|
||||
*/
|
||||
public ?array $migrationStatusKV = null;
|
||||
|
||||
// The $migrationSourceSchema defines the remote schema for the source table, and is set in the constructor
|
||||
public ?string $migrationSourceSchema;
|
||||
|
||||
// The source table in the remote repos (default defined in the XML) must be declared here, set in the constructor
|
||||
public ?string $migrationSourceTable;
|
||||
|
||||
//=================================================================================================================
|
||||
// WAREHOUSE DECLARATIONS
|
||||
// ----------------------
|
||||
// This section handles the warehousing configuration for the class. If a data table is eligible to be ware-
|
||||
// housed, then this section contains all the configuration information, including permissions, for the destination
|
||||
// repository. Note that we need to support bi-directional flow for data.
|
||||
//
|
||||
// Terms/Definitions:
|
||||
// ------------------
|
||||
// HOT -- data is in production
|
||||
// COOL -- data has been warehoused, maintains schema, but with indexing changes.
|
||||
// COLD -- data has been warehoused but formatted to the destination schema, usually CSV.
|
||||
// WARM -- indicates any data moving from COLD -> HOT
|
||||
//
|
||||
// Design Features:
|
||||
// ----------------
|
||||
// Supported
|
||||
// This is a boolean value that indicates if the class supports warehousing. If this is set to false, then
|
||||
// warehousing requests for the class will be rejected.
|
||||
//
|
||||
// Remote Support
|
||||
// --------------
|
||||
// This is a boolean value that indicates if the class will support a warehouse source outside of the Namaste
|
||||
// framework. If this is set to false, and a user submits a request defining the data source as a remote
|
||||
// repository, the request will be rejected.
|
||||
//
|
||||
// Automated
|
||||
// This is a boolean value that indicates if the class allows automated warehousing, meaning that data will be
|
||||
// warehoused once the qualifying condition has been met.
|
||||
//
|
||||
// Dynamic
|
||||
// Boolean value that, if set to true, indicates that the class will accept dynamic requests. Otherwise, the
|
||||
// warehousing operations will follow the interval schedule. Defaults to false.
|
||||
//
|
||||
// Interval
|
||||
// This is a string value that tells the AT_micro-service how often to run automated warehousing on the data.
|
||||
// D = Daily, M = 1st of every month, Q = 1st of every quarter, Y = 1st of every year
|
||||
// The default setting for this value should be monthly (M).
|
||||
//
|
||||
// Qualifier
|
||||
// This is a query string, similar to what you would provide to Namaste for a fetch operation, that establishes
|
||||
// the filter/criteria for moving data to the warehouse. If Supported is set to true, this cannot be blank.
|
||||
//
|
||||
// Override
|
||||
// Boolean value indicating if, and only for dynamic event requests, if the Qualifier can be overridden. If
|
||||
// set to true, the the event request must contain a valid query filter.
|
||||
//
|
||||
// Delete
|
||||
// This is a string value that tells Namaste what to do with the source data once successfully warehoused.
|
||||
// H = hard delete, S = soft delete
|
||||
// Note that this value overrides the $setDeletes setting.
|
||||
//
|
||||
//=================================================================================================================
|
||||
|
||||
public ?array $wareHouse = [
|
||||
WH_SUPPORTED => true, // must be set to true for data class to support any warehousing
|
||||
WH_REMOTE_SUPPORT => true, // must be set to true to import data into this class from remote source
|
||||
WH_AUTOMATED => false, // must be set to true for warehousing to be automatically processed
|
||||
WH_DYNAMIC => true, // must be set to true to allow non-scheduled event requests
|
||||
WH_INTERVAL => 'M', // must be either D, M, Q or A, defaults to M
|
||||
WH_OVERRIDE => true, // true to allow an ad-hoc query filter or if WH_REMOTE_SUPPORT is true
|
||||
WH_DELETE => 'H', // must be either H, or S. Can be reset to T via meta. Default: H
|
||||
|
||||
// default warehouse query to grab records where the date is LT a value and the status is active:
|
||||
// the null value will be replaced with the value provided by the client in the wh request payload.
|
||||
WH_QUALIFIER => [
|
||||
DB_CREATED => [ OPERAND_NULL => [ OPERATOR_LT => [ null ] ] ],
|
||||
DB_STATUS => [ OPERAND_NULL => [ OPERATOR_EQ => [ STATUS_ACTIVE ]]],
|
||||
OPERAND_AND => null
|
||||
]
|
||||
];
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// CLASS METHODS...
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* __construct() -- public method
|
||||
*
|
||||
* we have a constructor to register the destructor.
|
||||
*
|
||||
* @author mike@givingassistant.org
|
||||
* @version 1.0
|
||||
*
|
||||
* HISTORY:
|
||||
* ========
|
||||
* 03-23-18 mks CORE-852: original coding
|
||||
* 09-09-19 mks DB-111: initialization of migration members moved to constructor b/c IDE warnings.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->authToken = NULL_TOKEN;
|
||||
$this->migrationSourceSchema = STRING_MYSQL; // or STRING_MONGO
|
||||
$this->migrationSourceTable = 'product_registrations';
|
||||
register_shutdown_function([$this, STRING_DESTRUCTOR]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* __clone() -- private function
|
||||
*
|
||||
* Silently disallows cloning of the object
|
||||
*
|
||||
* @author mike@givingassistant.org
|
||||
* @version 1.0
|
||||
*
|
||||
* @return null
|
||||
*
|
||||
* HISTORY:
|
||||
* ========
|
||||
* 03-23-18 mks CORE-852: original coding
|
||||
*
|
||||
*/
|
||||
private function __clone()
|
||||
{
|
||||
return(null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* __destruct() -- public function
|
||||
*
|
||||
* As of PHP 5.3.10 destructors are not run on shutdown caused by fatal errors.
|
||||
*
|
||||
* The destructor is registered as a shut-down function in the constructor -- so any recovery
|
||||
* efforts should go in this method.
|
||||
*
|
||||
* @author mike@givingassistant.org
|
||||
* @version 1.0
|
||||
*
|
||||
* HISTORY:
|
||||
* ========
|
||||
* 03-23-18 mks CORE-852: original coding
|
||||
*
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
// empty by design
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user