diff --git a/mocha-php/src/mocha-php/images/logo-error.svg b/mocha-php/src/mocha-php/images/logo-error.svg new file mode 100644 index 0000000..b7e7111 --- /dev/null +++ b/mocha-php/src/mocha-php/images/logo-error.svg @@ -0,0 +1,23 @@ + + + \ No newline at end of file diff --git a/mocha-php/src/mocha-php/include/BeforeLaunchEvent.inc.php b/mocha-php/src/mocha-php/include/BeforeLaunchEvent.inc.php index bae09f0..3217ada 100644 --- a/mocha-php/src/mocha-php/include/BeforeLaunchEvent.inc.php +++ b/mocha-php/src/mocha-php/include/BeforeLaunchEvent.inc.php @@ -1,5 +1,7 @@ IncludeTopNavigationBar = false; + $html->renderBeginErrorPage("Tenant not found", "Tenant not found"); + echo ("
The specified tenant does not exist or is not available.
"); + echo ("We apologize for the inconvenience. If you are a MochaPowered customer and require additional assistance please contact the Designated Support Contact within your organization. Otherwise, please check back later.
"); + $html->renderEndErrorPage(); return false; } else { $oms->setTenant($currentTenant); + if (count($path) == 1) + { + System::Redirect("~/" . $path[0] . "/d/home.htmld", true); + return false; + } } return true; }; diff --git a/mocha-php/src/mocha-php/include/mochacommon.inc.php b/mocha-php/src/mocha-php/include/mochacommon.inc.php index f223d6b..12656ef 100644 --- a/mocha-php/src/mocha-php/include/mochacommon.inc.php +++ b/mocha-php/src/mocha-php/include/mochacommon.inc.php @@ -4,7 +4,9 @@ use Mocha\Core\InstanceReference; use Mocha\Core\KnownAttributeGuids; use Mocha\Core\KnownInstanceGuids; use Mocha\Core\KnownRelationshipGuids; +use Mocha\Core\OmsContext; use Mocha\Oms\MySQLDatabaseOms; +use Mocha\UI\Renderers\HTML\HTMLRenderer; use Phast\System; function mocha_asset_get_physical_path($package, $version, $path) @@ -28,9 +30,24 @@ function mocha_get_oms() return $_SESSION["OMS"]; */ global $oms; + if ($oms === null) { - $oms = new MySQLDatabaseOms(System::GetConfigurationValue("Database.ServerName"), System::GetConfigurationValue("Database.PortNumber"), System::GetConfigurationValue("Database.DatabaseName"), System::GetConfigurationValue("Database.UserName"), System::GetConfigurationValue("Database.Password")); + try + { + $oms = new MySQLDatabaseOms(System::GetConfigurationValue("Database.ServerName"), System::GetConfigurationValue("Database.PortNumber"), System::GetConfigurationValue("Database.DatabaseName"), System::GetConfigurationValue("Database.UserName"), System::GetConfigurationValue("Database.Password")); + } + catch (\PDOException $ex) + { + $ctx = new OmsContext(); + $html = new HTMLRenderer($ctx, true); + $html->IncludeTopNavigationBar = false; + $html->renderBeginErrorPage("Mocha is currrently unavailable", "We are experiencing a service interruption"); + echo ("Your service will be restored as quickly as possible.
"); + echo ("We apologize for the inconvenience. If you are a MochaPowered customer and require additional assistance please contact the Designated Support Contact within your organization. Otherwise, please check back later.
"); + $html->renderEndErrorPage(); + die(); + } } $oms->setCurrentUser(mocha_get_current_user()); return $oms; diff --git a/mocha-php/src/mocha-php/lib/mocha/core/KnownAttributeGuids.inc.php b/mocha-php/src/mocha-php/lib/mocha/core/KnownAttributeGuids.inc.php index 457613c..4a750a3 100644 --- a/mocha-php/src/mocha-php/lib/mocha/core/KnownAttributeGuids.inc.php +++ b/mocha-php/src/mocha-php/lib/mocha/core/KnownAttributeGuids.inc.php @@ -15,6 +15,8 @@ class KnownAttributeGuids const Order = "{49423f66-8837-430d-8cac-7892ebdcb1fe}"; const MethodType = "{47ae57a9-7723-48a8-80f2-dd410d929e14}"; + const EvaluateWorkSet = "{62c28f9e-5ce8-4ce5-8a56-1e80f1af7f6a}"; + const ClassName = "c7e8d78ecfac4dacae242ac67a0ba9d3"; const ThemeName = "{8cfc012c-52fd-4a66-8b2f-1b9b5e4af474}"; @@ -25,7 +27,7 @@ class KnownAttributeGuids const TargetURL = "970F79A09EFE4E7D92869908C6F06A67"; - const UserName = "960FAF025C5940F791A720012A99D9ED"; + const UserName = "{960faf02-5c59-40f7-91a7-20012a99d9ed}"; const PasswordHash = "F377FC294DF14AFB96434191F37A00A9"; const PasswordSalt = "8C5A99BC40ED4FA2B23FF373C1F3F4BE"; diff --git a/mocha-php/src/mocha-php/lib/mocha/core/KnownInstanceGuids.inc.php b/mocha-php/src/mocha-php/lib/mocha/core/KnownInstanceGuids.inc.php index d503a9a..f34aced 100644 --- a/mocha-php/src/mocha-php/lib/mocha/core/KnownInstanceGuids.inc.php +++ b/mocha-php/src/mocha-php/lib/mocha/core/KnownInstanceGuids.inc.php @@ -71,8 +71,12 @@ class KnownInstanceGuids const WorkSet__RelatedInstance = "{d9634929-0bb4-482a-85cc-9c8f1251556f}"; const WorkSet_ClassForMethod = "{d8eeff45-acbc-4031-8b09-bf9b8085c185}"; const WorkSet__TaskRelatedInstance = "{d3860252-491e-469e-939e-702d56d88063}"; + const WorkSet__ClassOfInstanceToCreate = "{1f1170ac-ee7e-405c-99bb-b922f3d598fa}"; const SystemAttributeRoutine_GetGlobalIdentifier = "{1a7ebec3-dc02-4c9b-a5df-0c72646453c9}"; const SystemAttributeRoutine_GetInstanceText = "{b024abd6-1f2b-495a-9da3-c9ce29fb0c2f}"; + + const SystemInstanceSetRoutine_CreateInstance = "{f46135f6-e812-49e6-9755-d63eb6ef1305}"; + const SystemInstanceSetRoutine_GetUserForUserNameParm = "{430f572d-d116-4b04-97b2-65a9e9230ce5}"; } ?> \ No newline at end of file diff --git a/mocha-php/src/mocha-php/lib/mocha/core/KnownRelationshipGuids.inc.php b/mocha-php/src/mocha-php/lib/mocha/core/KnownRelationshipGuids.inc.php index 574efee..4dc1136 100644 --- a/mocha-php/src/mocha-php/lib/mocha/core/KnownRelationshipGuids.inc.php +++ b/mocha-php/src/mocha-php/lib/mocha/core/KnownRelationshipGuids.inc.php @@ -227,7 +227,9 @@ class KnownRelationshipGuids const Integration_ID_Usage__for__Integration_ID = "d8d981ec768640dab89f006c85042444"; const Conditional_Select_from_Instance_Set_Method__has__Conditional_Select_from_Instance_Set_Case = "b6715132b4384073b81d3ecf19584b7d"; - const Conditional_Select_from_Instance_Set_Case__for__Conditional_Select_from_Instance_Set_Method = "1c868a068fb7432d839b7a5a02a50eb6"; + const Conditional_Select_from_Instance_Set_Case__invokes__Executable_returning_Instance_Set = "{8fde1baa-ce2e-4245-a775-bc4c66eac7b5}"; + + const Conditional_Select_from_Instance_Set_Method__returns__Work_Set = "{49396bd0-b5a9-4384-99f4-2126d80b3b66}"; const Condition_Group__has_true_condition__Executable_returning_Attribute = "d955da3f7ef443748b86167c73434f75"; const Executable_returning_Attribute__true_condition_for__Condition_Group = "1acdefd1e1b445bb99e1bf73dea71da5"; diff --git a/mocha-php/src/mocha-php/lib/mocha/core/OmsContext.inc.php b/mocha-php/src/mocha-php/lib/mocha/core/OmsContext.inc.php index 0b73757..deb8739 100644 --- a/mocha-php/src/mocha-php/lib/mocha/core/OmsContext.inc.php +++ b/mocha-php/src/mocha-php/lib/mocha/core/OmsContext.inc.php @@ -38,49 +38,88 @@ } return $defaultValue; } - public function setWorkData(string|InstanceReference $parmId, $value) + public function setWorkData(InstanceReference|string|InstanceKey|array $parm, $value) { /** * @var \Mocha\Oms\MySQLDatabaseOms */ $oms = mocha_get_oms(); - $key = $parmId; - if ($key instanceof InstanceReference) + // "Work Data" are .. "smart" variables + // They can be restricted to a set of "valid classes" (via `Work Data.has valid Class`) + // They could potentially also do a whole bunch of other validations if we want them to + + $parm = $oms->normalizeInstanceReference($parm); + $key = $parm->GlobalIdentifier->__toString(); + + // When setting a Work Data, first check to make sure the passed-in value is appropriate + // for the given Work Data. If the Work Data is a Work Set, check to make sure the value + // is indeed an InstanceReference, and that its parent class is in the selection list of + // `Work Set.has valid Class` for the given Work Set. + + $expectedDataType = ""; + $actualDataType = ""; + if (!$oms->validateWorkDataType($parm, $value, $expectedDataType, $actualDataType)) { - $key = $key->GlobalIdentifier->__toString(); - if ($value === null) + $printBacktrace = false; + trigger_error("invalid work data (expected: " . $expectedDataType . ", got: " . $actualDataType . " [ " . $value . " ] " . ") for attribute " . $parm->InstanceKey . " @ " . $parm->GlobalIdentifier); + if ($printBacktrace) { - //echo ("[ set wd " . $parmId->InstanceKey->__toString() . " = null ]"); + debug_print_backtrace(); } - else + } + + // Now here's where we start fudging things... If the Work Data is a Work Set, and the + // value is a Class, AND the Work Set valid classes DOES NOT include `Class`, THEN we + // should *evaluate* the Class value *as a work set* and see if THAT value is of a class + // valid for the Work Set. This should only happen once. If we are satisfied, assign THAT + // value to the given Work Set and we're all good. + if ($oms->is_a($parm, KnownClassGuids::WorkSet)) + { + $Valid_Classes_for_Work_Set = $oms->getRelatedInstances($parm, KnownRelationshipGuids::Work_Set__has_valid__Class); + if ($oms->is_a($value, KnownClassGuids::Clasz)) { - if (is_string($value)) + if (!$oms->instanceSetContains($Valid_Classes_for_Work_Set, KnownClassGuids::Clasz)) { - //echo ("[ set wd " . $parmId->InstanceKey . " = STR'" . $value . "' ]"); + $Evaluated_Value_for_Class = $this->getWorkData($value); + if ($Evaluated_Value_for_Class !== null) + { + $pclass = $oms->getParentClass($Evaluated_Value_for_Class); + + if ($oms->instanceSetContains($Valid_Classes_for_Work_Set, $pclass)) + { + $value = $Evaluated_Value_for_Class; + echo ("Work Set evaluated for class OK"); + } + else + { + echo ("Evaluated value for Class not valid for Work Set "); + } + } + else + { + // echo ("Evaluated value for Class was null! "); + } } else { - //echo ("[ set wd " . $parmId->InstanceKey . " = IK'" . $value->InstanceKey . "' ]"); + echo ("Valid Classes for Work Set contains Class"); } } - - $expectedDataType = ""; - $actualDataType = ""; - if (!$oms->validateWorkDataType($parmId, $value, $expectedDataType, $actualDataType)) - { - //echo("invalid work data (expected: " . $expectedDataType . ", got: " . $actualDataType . ") for attribute " . $parmId->InstanceKey . " @ " . $parmId->GlobalIdentifier); - } } + $this->workData[$key] = $value; } - public function getWorkData(string|InstanceReference $parmId, $defaultValue = null) + public function getWorkData(InstanceReference|string|InstanceKey|array $parmId, $defaultValue = null) { - $key = $parmId; - if ($key instanceof InstanceReference) - { - $key = $key->GlobalIdentifier->__toString(); - } + /** + * @var \Mocha\Oms\MySQLDatabaseOms + */ + $oms = mocha_get_oms(); + + $parmId = $oms->normalizeInstanceReference($parmId); + $key = $parmId->GlobalIdentifier->__toString(); + if (array_key_exists($key, $this->workData)) { return $this->workData[$key]; diff --git a/mocha-php/src/mocha-php/lib/mocha/oms/Oms.inc.php b/mocha-php/src/mocha-php/lib/mocha/oms/Oms.inc.php index a76d72b..4606f08 100644 --- a/mocha-php/src/mocha-php/lib/mocha/oms/Oms.inc.php +++ b/mocha-php/src/mocha-php/lib/mocha/oms/Oms.inc.php @@ -29,6 +29,8 @@ $this->MethodImplementations = null; } + public abstract function getUserByUserName(string $username) : ?InstanceReference; + private function registerMethodImplementation(InstanceReference|string|InstanceKey $methodImplementationClass, MethodImplementation $implementation) { $methodImplementationClass = $this->normalizeInstanceReference($methodImplementationClass); @@ -39,6 +41,7 @@ { $this->registerMethodImplementation(KnownClassGuids::BuildAttributeMethod, new \Mocha\Oop\MethodImplementations\BuildAttributeMethodImplementation()); $this->registerMethodImplementation(KnownClassGuids::ConditionalSelectAttributeMethod, new \Mocha\Oop\MethodImplementations\ConditionalSelectAttributeMethodImplementation()); + $this->registerMethodImplementation(KnownClassGuids::ConditionalSelectFromInstanceSetMethod, new \Mocha\Oop\MethodImplementations\ConditionalSelectInstanceSetMethodImplementation()); $this->registerMethodImplementation(KnownClassGuids::EvaluateBooleanExpressionMethod, new \Mocha\Oop\MethodImplementations\EvaluateBooleanExpressionMethodImplementation()); $this->registerMethodImplementation(KnownClassGuids::GetAttributeBySystemRoutineMethod, new \Mocha\Oop\MethodImplementations\GetAttributeBySystemRoutineMethodImplementation()); $this->registerMethodImplementation(KnownClassGuids::GetAttributeMethod, new \Mocha\Oop\MethodImplementations\GetAttributeMethodImplementation()); @@ -373,8 +376,9 @@ echo ($this->getInstanceKeysString($instanceReferences, $separator)); } - public function instanceSetContains(array /*Instance ID:
| Property | -Value | -
|---|---|
| Name | -suv | -
| Instance Id | -- |
| Property | +Value | +
|---|---|
| Name | +suv | +
| Instance Id | ++ |
| Host Name | ++ |
| Environment Version | +58132 | +
| Confidence Level | +prod | +
| Status | +completed | +
| Tenant Name | +Status | +Tenant Type | +Data Center | +Charge | +Initial Term | +Renewal Term | +Tenant Start Date | +Tenant Expiration Date | +Purpose | +
|---|---|---|---|---|---|---|---|---|---|
| super | +Active | +Development | +Local | +No Charge | ++ | + | + | + | Default Tenant | +
| Property | +Value | +
|---|---|
| Backend | +mysql | +
| User | ++ |
| Host | ++ |
| Port | ++ |
| Status | +running | +