Page MenuHomeIn-Portal Phabricator

INP-1886 - Add value-clearing support for "kDateFormatter::UpdateSubFields" method
AcceptedPublic

Authored by alex on Nov 19 2024, 11:19 AM.

Details

Reviewers
erik
Test Plan

Code:

/** @var CategoriesItem $category */
$category = $application->recallObject('c', null, array('skip_autoload' => true));
$category->Clear();

// Set date from virtual.
$category->SetDBFieldsFromHash(array(
	'CreatedOn_date' => 1732023005,
	'CreatedOn_time' => 1732023005,
));
$category->UpdateFormattersMasterFields();
$test_result = $category->GetDBField('CreatedOn') == 1732023005 && $category->GetDBField('CreatedOn_date') == 1732023005 && $category->GetDBField('CreatedOn_time') == 1732023005;
echo 'Test 1: ' . ($test_result ? 'OK' : 'FAILED') . '<br/>' . PHP_EOL;

// Clear date from virtual.
$category->SetDBFieldsFromHash(array(
	'CreatedOn_date' => null,
	'CreatedOn_time' => null,
));
$category->UpdateFormattersMasterFields();
$test_result = $category->GetDBField('CreatedOn') === null && $category->GetDBField('CreatedOn_date') === null && $category->GetDBField('CreatedOn_time') === null;
echo 'Test 2: ' . ($test_result ? 'OK' : 'FAILED') . '<br/>' . PHP_EOL;

// Set date from combined.
$category->SetDBFieldsFromHash(array(
	'CreatedOn' => 1732023005,
	'CreatedOn_date' => 123,
	'CreatedOn_time' => 123,
	'CreatedOn_combined' => 1,
));
$category->UpdateFormattersMasterFields();
$test_result = $category->GetDBField('CreatedOn') == 1732023005 && $category->GetDBField('CreatedOn_date') == 123 && $category->GetDBField('CreatedOn_time') == 123;
echo 'Test 3: ' . ($test_result ? 'OK' : 'FAILED') . '<br/>' . PHP_EOL;

// Clear date from combined.
$category->SetDBFieldsFromHash(array(
	'CreatedOn' => null,
	'CreatedOn_date' => 456,
	'CreatedOn_time' => 456,
	'CreatedOn_combined' => 1,
));
$category->UpdateFormattersMasterFields();
$test_result = $category->GetDBField('CreatedOn') === null && $category->GetDBField('CreatedOn_date') == 456 && $category->GetDBField('CreatedOn_time') == 456;
echo 'Test 4: ' . ($test_result ? 'OK' : 'FAILED') . '<br/>' . PHP_EOL;

// Set date directly.
$category->SetDBFieldsFromHash(array(
	'CreatedOn' => 1732023005,
));
$category->UpdateFormattersSubFields(array('CreatedOn'));
$test_result = $category->GetDBField('CreatedOn') == 1732023005 && $category->GetDBField('CreatedOn_date') == 1732023005 && $category->GetDBField('CreatedOn_time') == 1732023005;
echo 'Test 5: ' . ($test_result ? 'OK' : 'FAILED') . '<br/>' . PHP_EOL;

// Clear date directly.
$category->SetDBFieldsFromHash(array(
	'CreatedOn' => null,
));
$category->UpdateFormattersSubFields(array('CreatedOn'));
$test_result = $category->GetDBField('CreatedOn') === null && $category->GetDBField('CreatedOn_date') === null && $category->GetDBField('CreatedOn_time') === null;
echo 'Test 6: ' . ($test_result ? 'OK' : 'FAILED') . '<br/>' . PHP_EOL;

Part 1

  1. in the IDE replace the $application->Run(); line in the /index.php with the above-shown code and save changes
  2. open the /index.php in the Web Browser
  3. confirm, that all tests pass

Part 2 - e-mail log

  1. login to Admin Console
  2. go to the ConfigurationWebsiteAdvanced section
  3. enable the Use Cron to run Scheduled Tasks system setting
  4. save changes
  5. go to the Logs & ReportsE-mail Log section
  6. delete all the records in that grid
  7. go to the User ManagementMailings section
  8. switch to the Email Queue tab
  9. delete all the records in that grid
  10. go to the User ManagementUsers section
  11. create a user in the Active status
  12. use the Decline toolbar button on the above-created user
  13. go to the User ManagementMailings section
  14. switch to the Email Queue tab
  15. confirm, that 1 record, representing the USER.DENY e-mail, is shown in the grid
  16. press the Process Queue toolbar button
  17. confirm, that no records are shown in the grid
  18. go to the Logs & ReportsE-mail Log section
  19. confirm, that 1 record representing the USER.DENY e-mail, is shown in the grid AND that record has a non-empty value in the Sent On column

Part 3 - orders

  • go to Admin Console
    1. go to the Website & ContentStructure & DataProducts section
    2. switch to the Products tab
    3. add a new tangible product with Price=$10.00 and Status=Active
    4. go to the ConfigurationE-commerceShipping section
    5. add new custom shipping, that will:
      • on the General tab: have ShippingType=handling,BaseFee=5
      • on the Shipping Zones tab: use single zone to cover for all countries
      • on the Brackets tab: have single infinity bracket
    6. go to the ConfigurationE-commercePayment Types section
    7. set the Check/MO payment type as primary
  • go to Front-End
    1. place an order using the above-created product/shipping type and primary payment type (use any fake address for testing)
  • go to Admin Console
    1. go to the E-commerceOrders section
    2. switch to the Pending tab
    3. select the sales order, that was just submitted on the Front-End
    4. press the Approve toolbar button
    5. switch to the To Ship tab
    6. select the sales order, that was just approved
    7. press the Ship toolbar button
    8. switch to the Processed tab
    9. open the sales order, that was just shipped for editing
    10. go to the Shipping tab
    11. confirm, that the Shipping Date/Time is populated
    12. close the editing window
    13. select the sales order, that was just shipped
    14. press the Clone toolbar button
    15. switch to the Incomplete tab
    16. open the sales order, that was just cloned for editing
    17. go to the Shipping tab
    18. confirm, that the Shipping Date/Time is empty

Part 4 - session logging

  1. login to Admin Console
  2. go to the ConfigurationWebsiteAdvanced section
  3. enable the Track database changes to change log system setting
  4. save changes
  5. re-login to the Admin Console for Active session log record to be created
  6. re-login to the Admin Console for the above-created session log record to be marked as Logged Out
  7. go to the Logs & ReportsSession Log section
  8. confirm, that above made re-login actions caused a Logged Out session log record to be created with both Session Start and Session End dates to be populated

Diff Detail

Repository
rINP In-Portal
Branch
/in-portal/branches/5.2.x
Lint
Lint ErrorsExcuse: Not fixing.
SeverityLocationCodeMessage
Errorcore/units/logs/session_logs/session_log_eh.php:38PHPCS.E.CodingStandard.Arrays.Array.SpaceAfterKeywordCodingStandard.Arrays.Array.SpaceAfterKeyword
Errorcore/units/logs/session_logs/session_log_eh.php:38PHPCS.E.Generic.PHP.LowerCaseKeyword.FoundGeneric.PHP.LowerCaseKeyword.Found
Errorcore/units/logs/session_logs/session_log_eh.php:71PHPCS.E.CodingStandard.Arrays.Array.SpaceAfterKeywordCodingStandard.Arrays.Array.SpaceAfterKeyword
Errorcore/units/logs/session_logs/session_log_eh.php:71PHPCS.E.Generic.PHP.LowerCaseKeyword.FoundGeneric.PHP.LowerCaseKeyword.Found
Errormodules/in-commerce/units/orders/orders_event_handler.php:2216PHPCS.E.CodingStandard.Commenting.InlineComment.SpacingBeforeCodingStandard.Commenting.InlineComment.SpacingBefore
Errormodules/in-commerce/units/orders/orders_event_handler.php:2216PHPCS.E.Generic.WhiteSpace.ScopeIndent.IncorrectGeneric.WhiteSpace.ScopeIndent.Incorrect
Unit
No Unit Test Coverage
Build Status
Buildable 1339
Build 1339: arc lint + arc unit

Event Timeline

alex created this revision.Nov 19 2024, 11:19 AM
alex requested review of this revision.Nov 19 2024, 11:19 AM
alex edited the test plan for this revision. (Show Details)Nov 19 2024, 11:22 AM
alex added a project: Restricted Project.
alex planned changes to this revision.Nov 21 2024, 12:56 AM

New data came in during LIVE testing: the kDBItem::UpdateFormattersSubFields is used too aggressively, which results in clearing already populated date/time virtual fields. Need to adjust code/test plan for that.

alex edited the test plan for this revision. (Show Details)Nov 21 2024, 8:05 AM
alex updated this revision to Diff 1289.Nov 21 2024, 8:08 AM

Reduce scope (set of fields) for which \kDBBase::UpdateFormattersSubFields method is used to prevent accidental data loss.

erik accepted this revision.Tue, Dec 10, 10:55 AM

All tests passed.

maybe, test plan should include requirement to have checked "Use Cron to run Scheduled Tasks" - otherwise visible email queue is usually empty.

detected error, not related to current task when creating product
Product was created by default in home category, so not shown on front-end. So, manipulating with product categories on product edit sections tab,
i got SQL error when trying delete product section.

RuntimeException: Column 'CategoryId' in where clause is ambiguous

This revision is now accepted and ready to land.Tue, Dec 10, 10:55 AM
alex edited the test plan for this revision. (Show Details)Wed, Dec 11, 5:31 AM
alex added a comment.Wed, Dec 11, 6:01 AM
In D497#10220, @erik wrote:

maybe, test plan should include requirement to have checked "Use Cron to run Scheduled Tasks" - otherwise visible email queue is usually empty.

Done.

detected error, not related to current task when creating product
Product was created by default in home category, so not shown on front-end. So, manipulating with product categories on product edit sections tab,
i got SQL error when trying delete product section.

RuntimeException: Column 'CategoryId' in where clause is ambiguous

I'll create a separate issue about an SQL error during removing a category association from the category item (e.g. product).