Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpublished repeaters items have 2048 instead of 2049 for status #36

Open
adrianbj opened this issue Oct 9, 2016 · 15 comments
Open

Unpublished repeaters items have 2048 instead of 2049 for status #36

adrianbj opened this issue Oct 9, 2016 · 15 comments

Comments

@adrianbj
Copy link

adrianbj commented Oct 9, 2016

Short description of the issue

As per the title

Expected behavior

I would expect that unpublished repeater items would also have StatusOn(1) and therefore be 2049.

Actual behavior

They end up with 2048

Optional: Suggestion for a possible fix

Not sure if this needs a fix because I don't really know if it's intended or not. It seems inconsistent to me, but I am guessing there is a valid reason, so maybe this is more of a question that an issue, but I am not sure.

@ryancramerdesign
Copy link
Member

The two statuses are equivalent. In some cases, I'll use them for temporary runtime purposes but don't recall if I'm doing that here or not. In any case, there's no need to worry about the differing statuses, they should be inconsequential.

@adrianbj
Copy link
Author

Unfortunately it doesn't seem to be inconsequential in this case - a repeater item with 2049 shows as "New", rather than unpublished. If you are creating an unpublished repeater via the API you need to make sure it is set to 2048 and not 2049 or it simply doesn't work as none of content of the repeater is shown.

@adrianbj
Copy link
Author

@isellsoap - any chance of re-opening this please. I do think there is more to it than Ryan mentioned. I could be wrong of course, but I would really appreciate a little more clarification on my last point.

Perhaps @ryancramerdesign will still remember to get back to me, but I know how many Github notifications he must get and it must be hard to keep track of them all. Having it open again will be an unavoidable reminder :)
Thanks!

@isellsoap isellsoap reopened this Oct 13, 2016
@ryancramerdesign
Copy link
Member

Taking a closer look, it does look like FieldtypeRepeater uses the Page::statusOn for some identification. How are you creating your Repeater pages? Make sure you are using one of the built-in methods that are setup for this purpose, i.e.

$item = $page->repeater_field->makeNewItem();

or this

$field = $fields->get('repeater_field');
$item = $field->type->getBlankRepeaterPage($page, $field);

This is good to do not only for making sure it has the right status for repeaters, but also because it will use existing blank ready pages when available. If you are already using one of these and still seeing the wrong status, please let me know.

@adrianbj
Copy link
Author

Yeah I noticed that use of statusOn. I guess I thought that the inconsistency was still a little weird.

I have put together a one click script that converts a PageTable field to a Repeater or Repeater Matrix field. It converts everything beautifully including all fields, templates, and of course the content of each of the item sub-pages. The thing is that I am not using makeNewItem because I am changing the parent of sub-page from the PageTable parent to the relevant Repeater parent (with some config changes), so I think in this case my hack to manually remove StatusOn is probably the best solution.

Anyway, I have a working solution and as long as you are happy, then I guess this isn't really a problem.

@adrianbj
Copy link
Author

Sorry @ryancramerdesign - more thoughts on this - it currently seems impossible to use either of these on a repeater item, even if they were created via the admin GUI:

$item->addStatus(Page::statusUnpublished);
$item->removeStatus(Page::statusUnpublished);

Am I missing something?

@adrianbj adrianbj reopened this Oct 13, 2016
@ryancramerdesign
Copy link
Member

Adrian, check out the comments at the top of the FieldtypeRepeater.module file, it has a few notes in there about how Repeater pages use Page statuses and what the different combinations mean. I'm not positive this is the reason for what you are seeing, so you might also want to double check that the repeater items originated from an unformatted value (i.e. outputFormatting == false).

@isellsoap
Copy link
Collaborator

@adrianbj Does @ryancramerdesign’s suggestion fix this issue for you? Can it be closed?

@adrianbj
Copy link
Author

adrianbj commented Nov 6, 2016

I have read the notes about what the different statuses mean, but I still think something is broken when making changes to the status via the API.

Here's a bunch of sequential screenshots that hopefully shows the issue clearly.

1) Initial state - everything setup completely via the admin GUI:

screen shot 2016-11-06 at 10 52 58 am

Looking at the pages via PHPMyAdmin I see that the status of each is:
#1 - 1
#2 - 2048

2) Now we run this code:

$p = $pages->get(1);
$p->of(false);
foreach($p->repeatertest as $item) $item->removeStatus(Page::statusUnpublished);
$p->save("repeatertest");

which results in this:
screen shot 2016-11-06 at 10 56 08 am
which looks fine, but now the status of each page is:
#1 - 0
#2 - 1

3) Now we run this code:

$p = $pages->get(1);
$p->of(false);
foreach($p->repeatertest as $item) $item->addStatus(Page::statusUnpublished);
$p->save("repeatertest");

which results in this:
screen shot 2016-11-06 at 10 58 52 am

which seems weird because the first one is now "New" and the status of each page is:
#1 - 2048
#2 - 2049

Does that help to explain the problem? Or am I still missing something?

@CalleRosa40
Copy link

I agree with @adrianbj that this behavior is inconsistent and quite confusing. Running $repeaterItem->addStatus(Page::statusUnpublished) should really unpublish the item. Without having to remove statusOn, that is. It would be great if this were fixed, especially since Repeaters seem to receive an overhaul at the moment anyway.

Apart from that, @ryancramerdesign and all collaborators, ProcessWire is a totally awesome system. Thanks a lot for it!

@netcarver
Copy link
Collaborator

@adrianbj Hi Adrian, I note this issue is quite old now, is it still relevant or has it been fixed/superseded?

@adrianbj
Copy link
Author

adrianbj commented Feb 6, 2019

Hey @netcarver - I think it's a still a mess that needs cleaning up - it's a weird exception which makes API manipulation not work as expected. It certainly hasn't been fixed AFAIK.

@joer80
Copy link

joer80 commented Apr 22, 2019

I can confirm this is still an issue. Even if you create the repeater item with the admin, to unpublish via api you must do this or it doest work right:

$l->addStatus(Page::statusUnpublished);
$l->removeStatus(Page::statusOn);

@adrianbj
Copy link
Author

Thanks for your input @joer80 - this has been around for a long time :)

@ryancramerdesign
Copy link
Member

@joer80 you've got it mostly right but you'll want to set the status directly rather than using addStatus/removeStatus calls. That's because addStatus/removeStatus are what you want to use when you want to add or remove some status without affecting other statuses that might be present. That's not what you want here since repeater combines the unpublished status with others to mean different things (see here), which likely don't apply to your API usage. (Though it's good to know what they are, just in case they are useful for your purpose). So to unpublish, keep it simple and just set the status directly:

$item->status = Page::statusUnpublished;

or to publish set status to 0 (no status) or 1 (statusOn flag):

$item->status = Page::statusOn;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants