User tests: Successful: Unsuccessful:
Solved issue from #5596
The issue:
If you have a category and a related sub-category and unpublish the category, both get unpublished. If you now publish the sub-category, the message will be "Successful" but the sub-category hasn't been published. This message should be changed.
The solution:
I needed to create a new language constant, because there was none that could be used. Therefore I created the constant, COM_CATEGORIES_PUBLISHING_NOT_SUCCESSFUL="Publishing was not successful."
If a sub-category gets published, there is a check that checks for the related main category and if this one is active. If not, an error is set. The problem was, that there was no check if an error occurred during this process and therefor the error message always said that everything was fine and published. I created a new variable $errors = $model->getErrors(); which will inherit all the errors that are set. After that I also needed to create the check and throw an error.
How to test:
Expected Result after solution.
An error message will be displayed that the publishing was not successful.
Worked as a group on that issue: @icampus, @FPerisa, @flow87 and @xsability
Status | New | ⇒ | Pending |
Labels |
Added:
?
?
|
Title |
|
Category | ⇒ | Administration UI/UX |
Easy | No | ⇒ | Yes |
I have tested this item successfully on 931d184
Tested according to instruction. Results as expected.
However:
When publishing subcategory in list view, error message appears and subcategory remains unpublished.
When publishing subcategory in detail view, no error message appears and subcategory is published while category is not.
I looked a bit further into this.
We can indeed use libraries/legacy/controller/admin.php to display the right message, but it is necessary to take into account that the error/exception is not only possible for category but also for any extension using nested.
In core this is the case for Menus and Tags.
I propose this:
diff --git a/administrator/language/en-GB/en-GB.com_categories.ini b/administrator/language/en-GB/en-GB.com_categories.ini
index f6b6659..08232e7 100644
--- a/administrator/language/en-GB/en-GB.com_categories.ini
+++ b/administrator/language/en-GB/en-GB.com_categories.ini
@@ -59,4 +59,6 @@
COM_CATEGORIES_N_ITEMS_DELETED="%d categories successfully deleted."
COM_CATEGORIES_N_ITEMS_DELETED_1="%d category successfully deleted."
+COM_CATEGORIES_N_ITEMS_FAILED_PUBLISHING="Failed publishing %d categories."
+COM_CATEGORIES_N_ITEMS_FAILED_PUBLISHING_1="Failed publishing %d category."
COM_CATEGORIES_N_ITEMS_PUBLISHED="%d categories successfully published."
COM_CATEGORIES_N_ITEMS_PUBLISHED_1="%d category successfully published."
diff --git a/administrator/language/en-GB/en-GB.com_menus.ini b/administrator/language/en-GB/en-GB.com_menus.ini
index 57eba66..64997f9 100644
--- a/administrator/language/en-GB/en-GB.com_menus.ini
+++ b/administrator/language/en-GB/en-GB.com_menus.ini
@@ -144,4 +144,6 @@
COM_MENUS_N_ITEMS_DELETED="%d menu items successfully deleted."
COM_MENUS_N_ITEMS_DELETED_1="%d menu item successfully deleted."
+COM_MENUS_N_ITEMS_FAILED_PUBLISHING="Failed publishing %d menu items."
+COM_MENUS_N_ITEMS_FAILED_PUBLISHING_1="Failed publishing %d menu item."
COM_MENUS_N_ITEMS_PUBLISHED="%d menu items successfully published."
COM_MENUS_N_ITEMS_PUBLISHED_1="%d menu item successfully published."
diff --git a/administrator/language/en-GB/en-GB.com_tags.ini b/administrator/language/en-GB/en-GB.com_tags.ini
index 281167c..015fb6e 100644
--- a/administrator/language/en-GB/en-GB.com_tags.ini
+++ b/administrator/language/en-GB/en-GB.com_tags.ini
@@ -106,4 +106,6 @@
COM_TAGS_N_ITEMS_DELETED="%d tags successfully deleted."
COM_TAGS_N_ITEMS_DELETED_1="%d tag successfully deleted."
+COM_TAGS_N_ITEMS_FAILED_PUBLISHING="Failed publishing %d tag."
+COM_TAGS_N_ITEMS_FAILED_PUBLISHING_1="Failed publishing %d tags."
COM_TAGS_N_ITEMS_PUBLISHED="%d tags successfully published."
COM_TAGS_N_ITEMS_PUBLISHED_1="%d tag successfully published."
diff --git a/libraries/legacy/controller/admin.php b/libraries/legacy/controller/admin.php
index 0aee760..015feee 100644
--- a/libraries/legacy/controller/admin.php
+++ b/libraries/legacy/controller/admin.php
@@ -209,7 +209,16 @@
$model->publish($cid, $value);
+ $errors = $model->getErrors();
+
if ($value == 1)
{
- $ntext = $this->text_prefix . '_N_ITEMS_PUBLISHED';
+ // Check is ancestor has lower state
+ if (!empty($errors))
+ {
+ $ntext = $this->text_prefix . '_N_ITEMS_FAILED_PUBLISHING';
+ }
+ else
+ {
+ $ntext = $this->text_prefix . '_N_ITEMS_PUBLISHED';
+ }
}
elseif ($value == 0)
This would work when using the list display and has the advantage of being able to customise the message per extension.
The exception is thrown line 991 of ~ROOT/libraries/joomla/table/nested.php
if (!empty($rows))
{
$e = new UnexpectedValueException(
sprintf('%s::publish(%s, %d, %d) ancestors have lower state.', get_class($this), $pks, $state, $userId)
);
$this->setError($e);
return false;
}
If we want to prevent publishing the subcategory when we edit its details and throw a specific message, I guess this should be done in the save method for the category model (menu and tags too).
What do you think?
@brianteeman
Would the string values I proposed above fit OK in en-GB?
@infograf768 the strings need to follow the style guide. So they need a
period at the end
On 11 Oct 2015 9:29 am, "infograf768" notifications@github.com wrote:
@brianteeman https://github.com/brianteeman
Would the string values I proposed above fit OK in en-GB?—
Reply to this email directly or view it on GitHub
#8038 (comment).
@brianteeman
Already corrected above some time ago (see #8038)
To avoid using this string for any model error, I would even change to:
diff --git a/libraries/legacy/controller/admin.php b/libraries/legacy/controller/admin.php
index 0aee760..af79e44 100644
--- a/libraries/legacy/controller/admin.php
+++ b/libraries/legacy/controller/admin.php
@@ -209,7 +209,23 @@
$model->publish($cid, $value);
+ $errors = $model->getErrors();
+
if ($value == 1)
{
- $ntext = $this->text_prefix . '_N_ITEMS_PUBLISHED';
+ // Check is ancestor has lower state
+ if (!empty($errors))
+ {
+ foreach ($errors as $error)
+ {
+ if (strpos($error, 'ancestors have lower state') !== false)
+ {
+ $ntext = $this->text_prefix . '_N_ITEMS_FAILED_PUBLISHING';
+ }
+ }
+ }
+ else
+ {
+ $ntext = $this->text_prefix . '_N_ITEMS_PUBLISHED';
+ }
}
elseif ($value == 0)
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-10-11 17:21:37 |
Closed_By | ⇒ | zero-24 |
Thank you for your additions, I haven't thought about that.
I am new to Joomla and this was my first PR, so thank you for your help!
@kathastaden
No p.
Please test though.
I have tested this item successfully on 931d184
Test was successful, following the test instructions.
This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8038.