XF 2.2 Create thread and set older date?

Robert9

Well-known member
service/thread/creator

Code:
protected function finalSetup()
    {
        $date = time();

        $this->thread->post_date = $date;
        $this->thread->last_post_date = $date;
        ...
        $this->post->post_date = $date;
        ...
    }

Here I can not attack.

Then I can do only an automatic edit after creating a thread?
[/CODE]
 
Last edited:
So i do something funny:

Code:
class Creator extends XFCP_Creator
{
    protected function finalSetup()
    {
        $reply = parent::finalSetup();

        $date = time() - 2592000;
        $this->thread->post_date = $date;
        $this->thread->last_post_date = $date;
        $this->post->post_date = $date;

    return $reply;
    }

}

It works! And it works for every new thread in the forum.
But I want this to work only when a new thread is done with my new addon.
How can I make a difference?


new add-on
add a form
add new thread
be the only one to use the extension for finalsetup

How can I do that?

$globalSpecialSuperVar = 1;

Code:
class Creator extends XFCP_Creator
{
    protected function finalSetup()
    {
        $reply = parent::finalSetup();
        get global!
        if $globalSpecialSuperVar == 1;
        {
                $date = time() - 2592000;
                $this->thread->post_date = $date;
                $this->thread->last_post_date = $date;
                $this->post->post_date = $date;
        }
        return $reply;
    }
 
To edit the date is a lot of work.
I have to change it before saving.
There's an app (or add-in in this case) for that. And it is free. Don't have the link handy but it is Change Post Date by Xon and it lets you edit post dates post-hoc. I use when I do a draft in a private forum, then move it to a public one and want the post date in the public forum to be the date of the move, not the date I wrote it. But it could be used in any scenario. Doesn't automate it, of course, as you seem to be trying to do. Also comes with a permission so you can control which user groups can use it.
 
Thank you, there are at least three add-ons for this, but my question is not to change date of thread/post by hand.

The point is how I can extend a class and use this extension only, when it is called from my new addon.


XF > creates a thread like always

new add-on > creates a thread, but set the date to a date in the past.
 
Last edited:
What is the normal way for: Hey, it is me who wants to create a new thread; I am special, please change the postDates!
 
Last edited:
Solved for tonight with:

set $GLOBALS['r9_qc_post_date'] in my index; then extend service/thread/creator

Code:
    protected function finalSetup()
    {
        $reply = parent::finalSetup();
       
        if (isset($GLOBALS['r9_qc_post_date']))
        {  
            $date = time() - 2592000;
            $this->thread->post_date = $date;
            $this->thread->last_post_date = $date;
            $this->post->post_date = $date;
        }

        return $reply;
    }


But there must be another way to extend and tell where we come from?
 
Globals are ugly and should be avoided if possible.

More sane approach:
PHP:
class Creator extends XFCP_Creator
{
    protected ?int $postDate = null;
  
    public function setPostDate(?int $postDate): void
    {
        $this->postDate = $postDate;
    }
  
    protected function finalSetup()
    {
        $reply = parent::finalSetup();
      
        if ($this->postDate !== null)
        {
            $this->thread->post_date = $this->postDate;
            $this->thread->last_post_date = $this->postDate;
            $this->post->post_date = $this->postDate;
        }
      
        return $reply;
    }
}
 
Thank you very much. Now I can feed the class, and check if feeded.

void is a return-only type declaration indicating the function does not return a value, but the function may still terminate.
This void is needed here, or just good to have, why?



You may want to bring more light in my dark life, please?

Do you have a hint how to manipulate the DefinitionSet(s?) of thread custom fields?

Example: Output at thread:

fieldId <> display_order
color 1
size 2
weight 3
year 4

but in my form i want to have

year 1
color 2
size 3
weight 4

XF/CustomField/...

public function setDefinitionSet(DefinitionSet $definitionSet)

set display_order of fieldID year to 1

How should $definitionSet look like? How I fetch it?


$lala = getDefinitionSet->fieldId

now manipulate what? > display_order

how to -> setDefinitionSet($lala)

How can I get $lala without being protected?
 
This void is needed here, or just good to have, why?
It is not required but IMHO nice to have so it's immediately clear that nothing will ever be returned from that method (and static analyzers as well as PHP runtime can check this)

You may want to bring more light in my dark life, please?

Do you have a hint how to manipulate the DefinitionSet(s?) of thread custom fields?
Not without taking a look at the code but I'm pretty sure there is a way to achieve this.
 
We have
xf/customfield

xf/entity/abstractfield
xf/entity/abstractfieldmap


Code:
            $fieldSet = $thread->custom_fields;
            $fieldDefinition = $fieldSet->getDefinitionSet();

->filterGroup
->Filter('fieldId')
->filterEditable($fieldSet, 'user');
->filterEditable($fieldSet, 'moderator');
->filterEditable($fieldSet, $editMode)
->filterOnly($this->forum->field_cache);
->getFieldDefinitions()


What I need is a setter to
setFieldIdDisplayOrder(fieldId, displayOrder)
 
Last edited:
Top Bottom