How do I change an entry’s status from Close to Open from outside code (running an UPDATE)?
Posted: 12 July 2008 02:53 PM   [ Ignore ]  
Grad Student
Rank
Total Posts:  52
Joined  10-03-2007

I’d like to simply do:
UPDATE exp_weblog_titles Set status = ‘open’ WHERE entry_id = $entry_id

but I’ve figured out that doesn’t do it.

I then looked at the database record before and after a manual status chanegd from Closed to Open, and I think all of these columns were changed besides status: versioning_enabled, entry_date, edit_date


So I changed my code to change all 4 columns…..but the web page showing the entries doesn’t show the newly updated item?

Am I doing something wrong?  Is there some other place I need to update or affect in the database in order for the {exp:weblog:entries} to show the entry set to open by outside code?


By the way, if I login as admin to the control panel, do an Edit for that entry, and simply click the Update button…it shows up.  So I’m thinking there is just something I’m not updating properly.

In case anyone’s wondering…I’m going through all of this to implement a one-touch approve process.  I’ve basically built a fully moderated Discussion Forum.  I’m using the a section as the forum; a form that creates a new entry which status defaults to Closed.  On submission of that form, an email is sent to a person who sees the body of the post, and I include a link to the outside code (that link contains the entry_id of that entry).  If the person receiving that email thinks the post should be live, they simply click the link.

(By the way…the EEmail class really rocks!)

Anyway, that’s the scenario.  The goal is easier approval for posts.  Unfortunately, the whole login to the control panel; choose Edit; choose the type and hit Search; click the item; click to the Options tab; toggle from Closed to Open; click Submit—- that whole process….soo much “work”, we wanted an email to be sent, and an easy one-click to approve link.


So…whatever help you can provide so that my UPDATE does the right thing to make the entry show up would be greatly appreciated.  Thanks so much.

-Aaron

Profile
 
 
Posted: 13 July 2008 11:49 AM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  19293
Joined  06-03-2002

You’ve got the right idea, Aaron, but you may need to clear caching for the changes to appear live.  Other columns will not be changed by the above query.  It would be good, though, before going further or describing how to clear the caches for you to share your full code so we can be sure you don’t also have syntax errors or other code that might be causing an issue.

 Signature 
Profile
MSG
 
 
Posted: 13 July 2008 11:59 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
RankRank
Total Posts:  288
Joined  09-28-2002

Here’s what I have so far. Changes only the entry status from the front end.

Profile
 
 
Posted: 13 July 2008 12:04 PM   [ Ignore ]   [ # 3 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  19293
Joined  06-03-2002

kirkaracha are you working with Aaron, or are you just doing something similar?  As an aside, your code needs some significant changes for security.  Right now you have a pretty serious SQL injection vulnerability because none of your data from POST is being validated or properly escaped.  Additional details can be found in our security guidelines documentation.

 Signature 
Profile
MSG
 
 
Posted: 13 July 2008 12:32 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
RankRank
Total Posts:  288
Joined  09-28-2002

Thank you for the pointer. I applied the security fix:

<?php

if(isset($_POST['entry_id']) && isset($_POST['section']) && (isset($_POST['status']) && $_POST['status'] != '')){
    $entry_id
= $_POST['entry_id'];
    
$section = $_POST['section'];
    
$status = $_POST['status'];

    global
$DB;
    
$data = array('status' => $status);
    
$where = array('entry_id' => $entry_id);

    
$DB->query($DB->update_string('exp_weblog_titles',$data,$where));

    
$heading = 'Status Changed';
    
$message = 'Status changed to <strong>' . $status . '</strong>.';
} else {
    $heading
= 'Couldn&#8217;t Change Status';
    
$message = 'Sorry, the status couldn&#8217;t be changed.';
}

$display_message
= '<h1>' . $heading . '</h1>' . "\r\r" . '<p>' . $message . '</p>' . "\r\r";

echo
$display_message;

?>

Also, the form is only visible to logged-in Super Admins, and the change status template is only accessible by Super Admins.

I’m working on my own on a similar requirement.

Profile
 
 
Posted: 13 July 2008 12:47 PM   [ Ignore ]   [ # 5 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  19293
Joined  06-03-2002

To clear caches after a successful update, add $FNS->clear_caching.

Aaron, please let me know if that helps you as well.

 Signature 
Profile
MSG
 
 
Posted: 13 July 2008 02:12 PM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  52
Joined  10-03-2007

That you guys!  You guys rock!!!

I haven’t had a chance to try this out yet, but that $FNS->clear_caching looks exactly like what I need.

By the way, I figured out this weekend that my time zone settings were ALL messed up.  My code could have been working all along, I just had the existing admin users setup with the default time zone, which WAS “Casablanca, ...”—I set the system time to Eastern US right before launch, but those previously created users were bad.

Anyway, I’ll let you know how it turns on in the next day or so.  Thanks again for your incredible support on these forums!

-Aaron

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120580 Total Logged-in Users: 47
Total Topics: 126616 Total Anonymous Users: 29
Total Replies: 665631 Total Guests: 309
Total Posts: 792247    
Members ( View Memberlist )