? ? Pending

User tests: Successful: Unsuccessful:

avatar kathastaden
kathastaden
9 Oct 2015

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:

  1. 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."

  2. 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:

  • Navigate to Category Manager
  • Create a main category
  • Create a sub-category that is related to the new main category
  • unpublish the main category
  • Both main & sub-category will get unpublished
  • Click on the sub-category and try to publish and check the message

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

avatar kathastaden kathastaden - open - 9 Oct 2015
avatar kathastaden kathastaden - change - 9 Oct 2015
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 9 Oct 2015
Labels Added: ? ?
avatar Preview Preview - test_item - 9 Oct 2015 - Tested successfully
avatar Preview
Preview - comment - 9 Oct 2015

I have tested this item :white_check_mark: 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.

avatar kathastaden kathastaden - change - 9 Oct 2015
Title
Category Manager: Articles :: Wrong message after publishing sub-category
Category Manager :: Wrong message after publishing sub-category
avatar zero-24 zero-24 - change - 10 Oct 2015
Category Administration UI/UX
avatar zero-24 zero-24 - change - 10 Oct 2015
Easy No Yes
avatar crommie crommie - test_item - 10 Oct 2015 - Tested successfully
avatar crommie
crommie - comment - 10 Oct 2015

I have tested this item :white_check_mark: 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.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8038.

avatar infograf768
infograf768 - comment - 10 Oct 2015

I confirm @crommie findings

Also, even modifying the code as the language string should not be of the type COM_CATEGORIES, I do not think this is the solution to this issue.

I guess the error should be checked and displayed through the category model.

avatar infograf768 infograf768 - alter_testresult - 10 Oct 2015 - infograf768: Tested unsuccessfully
avatar infograf768
infograf768 - comment - 11 Oct 2015

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?

avatar infograf768
infograf768 - comment - 11 Oct 2015

@brianteeman
Would the string values I proposed above fit OK in en-GB?

avatar brianteeman
brianteeman - comment - 11 Oct 2015

@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).

avatar infograf768
infograf768 - comment - 11 Oct 2015

@brianteeman
Already corrected above some time ago (see #8038)

avatar infograf768
infograf768 - comment - 11 Oct 2015

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)
avatar infograf768
infograf768 - comment - 11 Oct 2015

I created a new PR to simplify testing. Please test #8065

avatar zero-24 zero-24 - change - 11 Oct 2015
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2015-10-11 17:21:37
Closed_By zero-24
avatar zero-24 zero-24 - close - 11 Oct 2015
avatar kathastaden
kathastaden - comment - 11 Oct 2015

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!

avatar infograf768
infograf768 - comment - 11 Oct 2015

@kathastaden
No p.

Please test though. :smile:

Add a Comment

Login with GitHub to post a comment