Can only the wall be deleted automatically?

Tamás Varga Posted in Technical Support 3 years ago

Can it be solved that only the wall entries will be deleted automatically by the admin after 2 weeks?

Replies
Hungarian Tamás Varga Replied 3 years ago

Thank you very much, now it's so good, I'll fix the cron setup.

German Michael Zülsdorff Replied 3 years ago

OF COURSE?!?
Arsalan did not advise you to do anything like that!
You wanted to delete entries older than 14 days, hence it is sufficient to run this query once a day,
and not constantly when your site is being accessed.
This code has to be a separate file executed by CRON.
In doubt ask your provider which way to set up a daily cron job.

Hungarian Tamás Varga Replied 3 years ago

Of course I put it in the index.php file.

German Michael Zülsdorff Replied 3 years ago

2 months ago Arsalan wrote:

Yes it requires to have a cron job to be written

You did not put that code into index.php of Ossn?!?

Hungarian Tamás Varga Replied 3 years ago

Thank you so much for everything, I learned a lot. I wrote the change in the index.php file, testing it constantly.

German Michael Zülsdorff Replied 3 years ago

As a final exercise you may add the 'older than 14 days' condition to your query like

SELECT * FROM `ossn_object` WHERE subtype = 'wall' AND type = 'user' AND FROM_UNIXTIME(time_created) <= DATE_SUB(NOW(), INTERVAL 2 WEEK)

This time you should get 0 rows as a result, because all existing rows are not old enough to match the condition.

Ok, now that we know what has to happen on the SQL low level, we only have to 'translate' that missing type = 'user' condition to your PHP code

$listUser = $wall->GetPosts(array(
        'type' => 'user',
        'page_limit' => false,
        'wheres' => array(
                "(FROM_UNIXTIME(o.time_created) <= DATE_SUB(NOW(), INTERVAL 2 WEEK))"               
)));

That's it.

Hungarian Tamás Varga Replied 3 years ago

Super :)
enter image description here

German Michael Zülsdorff Replied 3 years ago

Almost perfect! ;)
All found rows are of subtype wall now
but your request was to leave the posts in Groups untouched, right?
That's why we still have to refine the query a bit to find only rows of type user

So, click Show query box to return to your former window
enter image description here

and change the query like

SELECT * FROM `ossn_object` WHERE subtype = 'wall' AND type = 'user'

execute this new query and verify the result:
there should be no more rows of type group

Hungarian Tamás Varga Replied 3 years ago

enter image description here

German Michael Zülsdorff Replied 3 years ago

Correct!
The query means:
SELECT all columns FROM the table ossn_object WHERE everything is valid - no restriction

That's why we're getting the complete number of rows.
Now remember what's inside the GetPosts function

            $default = array(
                    'subtype' => 'wall',
                    'order_by' => 'o.guid DESC'
            );

And that means: We want only rows of subtype wall
(the ordering is of no interest here, because in the end we would delete the rows anyway)

Okay, so back in phpmyadmin, let's change the query according to the GetPosts function
to look like

SELECT * FROM `ossn_object` WHERE subtype = 'wall'

Then click the GO button to execute the query

enter image description here
and make a screenshot of the result