Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F847911
D379.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Apr 19, 7:45 PM
Size
2 KB
Mime Type
text/x-diff
Expires
Sun, Apr 20, 7:45 PM (1 h, 2 m)
Engine
blob
Format
Raw Data
Handle
602691
Attached To
D379: INP-1781 - Respect sub-item status, when performing unique validation
D379.diff
View Options
Index: branches/5.2.x/core/kernel/utility/validator.php
===================================================================
--- branches/5.2.x/core/kernel/utility/validator.php
+++ branches/5.2.x/core/kernel/utility/validator.php
@@ -345,8 +345,20 @@
$res_temp = $this->Conn->GetOne( str_replace('%s', $this->dataSource->TableName, $sql) );
- $current_table_only = getArrayValue($params, 'current_table_only'); // check unique record only in current table
- $res_live = $current_table_only ? 0 : $this->Conn->GetOne( str_replace('%s', $this->Application->GetLiveName($this->dataSource->TableName), $sql) );
+ if ( getArrayValue($params, 'current_table_only') || !$this->dataSource->IsTempTable() ) {
+ // Check unique record only in current table.
+ $res_live = 0;
+ }
+ else {
+ $deleted_ids = $this->getTempTableDeletedIDs();
+ $live_sql = str_replace('%s', $this->Application->GetLiveName($this->dataSource->TableName), $sql);
+
+ if ( $deleted_ids ) {
+ $live_sql .= ' AND (' . $this->dataSource->IDField . ' NOT IN (' . implode(',', $deleted_ids) . '))';
+ }
+
+ $res_live = $this->Conn->GetOne($live_sql);
+ }
$res = ($res_temp == 0) && ($res_live == 0);
@@ -360,6 +372,56 @@
}
/**
+ * Returns IDs deleted in temp table.
+ *
+ * @return array
+ */
+ protected function getTempTableDeletedIDs()
+ {
+ $parent_prefix = $this->Application->getUnitOption($this->dataSource->Prefix, 'ParentPrefix');
+
+ if ( !$parent_prefix ) {
+ return array();
+ }
+
+ // 1. Get main IDs, that are edited in temp table.
+ $parent_table_name = $this->Application->GetTempName(
+ $this->Application->getUnitOption($parent_prefix, 'TableName'),
+ 'prefix:' . $parent_prefix
+ );
+
+ $sql = 'SELECT ' . $this->Application->getUnitOption($parent_prefix, 'IDField') . '
+ FROM ' . $parent_table_name;
+ $parent_temp_ids = $this->Conn->GetCol($sql);
+
+ // Main item not saved to db, but sub-item is validated (only possible via custom code).
+ if ( !$parent_temp_ids ) {
+ return array();
+ }
+
+ // 2. From above found IDs find sub-item IDs in LIVE table.
+ $foreign_key = $this->Application->getUnitOption($this->dataSource->Prefix, 'ForeignKey');
+ $foreign_key = is_array($foreign_key) ? $foreign_key[$parent_prefix] : $foreign_key;
+
+ $sql = 'SELECT ' . $this->dataSource->IDField . '
+ FROM ' . $this->Application->GetLiveName($this->dataSource->TableName) . '
+ WHERE ' . $foreign_key . ' IN (' . implode(',', $parent_temp_ids) . ')';
+ $live_ids = $this->Conn->GetCol($sql);
+
+ // Sub-items were never saved to LIVE table.
+ if ( !$live_ids ) {
+ return array();
+ }
+
+ // 3. Return IDs of LIVE table, that are no longer present (deleted) in TEMP table.
+ $sql = 'SELECT ' . $this->dataSource->IDField . '
+ FROM ' . $this->dataSource->TableName;
+ $temp_ids = $this->Conn->GetCol($sql);
+
+ return array_diff($live_ids, $temp_ids);
+ }
+
+ /**
* Check field value by user-defined alghoritm
*
* @param string $field field name
Event Timeline
Log In to Comment