Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F802593
D312.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
Mon, Feb 24, 9:02 PM
Size
3 KB
Mime Type
text/x-diff
Expires
Tue, Feb 25, 9:02 PM (19 h, 31 m)
Engine
blob
Format
Raw Data
Handle
575492
Attached To
D312: INP-1709 - Validate "Categories.FriendlyURL" field for uniqueness
D312.diff
View Options
Index: branches/5.2.x/core/install/english.lang
===================================================================
--- branches/5.2.x/core/install/english.lang
+++ branches/5.2.x/core/install/english.lang
@@ -268,6 +268,7 @@
<PHRASE Label="la_error_EmailTemplateBodyMissing" Module="Core" Type="1">RW1haWwgRGVzaWduIFRlbXBsYXRlIHNob3VsZCBjb250YWluIGF0IGxlYXN0ICIkYm9keSIgdGFnIGluIGl0Lg==</PHRASE>
<PHRASE Label="la_error_FileNotFound" Module="Core" Type="1">RmlsZSBub3QgZm91bmQ=</PHRASE>
<PHRASE Label="la_error_FileTooLarge" Module="Core" Type="1">RmlsZSBpcyB0b28gbGFyZ2U=</PHRASE>
+ <PHRASE Label="la_error_FriendlyUrlIsNotUnique" Module="Core" Type="1">VGhpcyBVUkwgaXMgY29uZmxpY3Rpbmcgd2l0aCBleGlzdGluZyBVUkwgYW5kIGNhbid0IGJlIHVzZWQ=</PHRASE>
<PHRASE Label="la_error_GroupNotFound" Module="Core" Type="1">Z3JvdXAgbm90IGZvdW5k</PHRASE>
<PHRASE Label="la_error_InvalidFieldName" Module="Core" Type="1">RmllbGQgZG9lc24ndCBleGlzdCBpbiAiJXMiIHVuaXQgY29uZmln</PHRASE>
<PHRASE Label="la_error_InvalidFileFormat" Module="Core" Type="1">SW52YWxpZCBGaWxlIEZvcm1hdA==</PHRASE>
Index: branches/5.2.x/core/units/categories/categories_config.php
===================================================================
--- branches/5.2.x/core/units/categories/categories_config.php
+++ branches/5.2.x/core/units/categories/categories_config.php
@@ -402,7 +402,12 @@
'default' => NULL
),
'FormSubmittedTemplate' => Array ('type' => 'string', 'default' => null),
- 'FriendlyURL' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''),
+ 'FriendlyURL' => Array (
+ 'type' => 'string',
+ 'unique' => array(),
+ 'error_msgs' => array('unique' => '!la_error_FriendlyUrlIsNotUnique!'),
+ 'not_null' => 1, 'default' => '',
+ ),
'ThemeId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'EnablePageCache' => Array (
Index: branches/5.2.x/core/units/categories/categories_event_handler.php
===================================================================
--- branches/5.2.x/core/units/categories/categories_event_handler.php
+++ branches/5.2.x/core/units/categories/categories_event_handler.php
@@ -1369,6 +1369,41 @@
}
/**
+ * Validates category data.
+ *
+ * @param kEvent $event Event.
+ *
+ * @return void
+ */
+ protected function OnBeforeItemValidate(kEvent $event)
+ {
+ parent::OnBeforeItemValidate($event);
+
+ /** @var kDBItem $object */
+ $object = $event->getObject();
+
+ $friendly_url = $object->GetDBField('FriendlyURL');
+
+ if ( strlen($friendly_url) && $friendly_url != $object->GetOriginalField('FriendlyURL') ) {
+ $sql = 'SELECT CategoryId
+ FROM %s
+ WHERE NamedParentPath = ' . $this->Conn->qstr('Content/' . $friendly_url);
+ $duplicate_id = $this->Conn->GetOne(sprintf($sql, $object->TableName));
+
+ if ( $duplicate_id === false && $object->IsTempTable() ) {
+ $duplicate_id = $this->Conn->GetOne(sprintf(
+ $sql,
+ $this->Application->GetLiveName($object->TableName)
+ ));
+ }
+
+ if ( $duplicate_id !== false ) {
+ $object->SetError('FriendlyURL', 'unique');
+ }
+ }
+ }
+
+ /**
* Sets correct status for new categories created on front-end
*
* @param kEvent $event
Event Timeline
Log In to Comment