[Snippet] save_content_externally
#1
Posted 28 March 2008 - 11:43 AM
File Submitter: Cris D.
File Submitted: 28 Mar 2008
File Updated: 2 Aug 2008
File Category: Miscellaneous
Snippet: save_content_external
Version: 1.0
Author: Cris D
Date: 2008/03/28
For: Etomite V 0.6.1.4
Uses: Basically, it creates new etomite pages without having to use the manager.
It collects variables and saves them to a new site document under a parent you specify.
Document variables are collected from (in order of priority)
1) $_POST variables with the $prefix pre-pended
2) snippet call parameters sent in the snippet call
3) snippet default parameters set in the snippet
NOTE: To use this snippet for 0.6.1.4 and earlier, you will need to update your manager/processors/cache_sync.class.processor.php file.
See Etomite forum thread: http://www.etomite.com/index.php?s=...ost&p=46982 for more detail. If you do not, you will get a "no file exists" error.
For Etomite V1.0 and later, this modification has already been made.
This snippet collects $_POST['params']first then if blank, uses snippet call and in-snippet parameters as defaults.
Installation Instructions:
Copy and paste this text file to your snippet library.
Either call this snippet by placing it on a page and pointing the form action="nn" to it or use $etomite->runSnippet() to call it.
Testing can be done easily by manually placing the $_POST['vars']; in the top of the snippet until you work out what you want to actually send to it!
2008/06/08 Upon review, I discovered that the delete action actually removes the document from the table: it does not mark it as deleted-to be purged later when the recycle bin is emptied. This action can not be undone. For a safer way of deleting a document, the deleted='1', deletedon='[timestamp]' and deletedby='['internalKey']' could be used. The deleted, deletedon and deletedby fields have not been included to be collected in this snippet, but could be added to the CODEswitch ($action){case 'delete': part quite easily.
CHANGELOG: 2008/08/02
Fixed typo with $_SESSION['internakKey']
Changed default user to 1 (admin) instead of '0'- NULL
Warning: This snippet plays with the etomite_site_content table. It creates documents on the fly and if you accidentally pass parameters to the table that arte incorrect, you can completely stop your site (and manager) from functioning! The default parameters being passed are OK so if in doubt, don't send it! If you know what you are doing and still want to send parameters and stuff it up, all can be restored by simply using phpMyAdmin to delete the documents you have created. This snippet is sailing close to the wind with manager modifications: if use of the snippet causes major problems with your installation because you are passing invalid parameters- you are on your own. Be warned!
Click here to download this file
#2
Posted 28 March 2008 - 12:55 PM
#3
Posted 28 March 2008 - 12:56 PM
#4
Posted 28 March 2008 - 12:59 PM
#5
Posted 01 August 2008 - 07:52 PM
#6
Posted 01 August 2008 - 10:26 PM
If you know the values of your parents, you could easily create an array of parents you want to create:
$groups=array(group1, group2,group3);
foreach($groups as $g){
$params=array('parent'=>$g);
$ids[]=$etomite->runSnippet('save_content_external',$params);
}
print_r($ids);
Glad you can use it...
Edited by Cris D., 01 August 2008 - 10:31 PM.
#7
Posted 01 August 2008 - 10:51 PM
The biggest problem I had getting the page trees created turned out to be (I think) a bug in runSnippet (reported to the tracker).
#8
Posted 02 August 2008 - 01:17 AM
$defaultUser= isset($_SESSION['internakKey']) ? $_SESSION['internalKey'] : '0';should be
$defaultUser= isset($_SESSION['internalKey']) ? $_SESSION['internalKey'] : '0';
#9
Posted 02 August 2008 - 06:39 AM
#10
Posted 03 August 2008 - 06:52 PM
It may help others work out how to solve other similar problems
// create a group and add pages into it
// params group (name - text) pages (id,id)
// returns group id or message
$sql = "INSERT INTO ".$etomite->db."documentgroup_names(name) VALUES ('$name');";
$rs = mysql_query($sql);
if(!$rs){
return "An error occured while attempting to create the new group ($name).";
}
if(!$key=mysql_insert_id()) {
return "Couldn't get the id for group $name!";
}
foreach (explode(',' , $pages) as $id) {
$sql = "INSERT INTO ".$etomite->db."document_groups(document_group, document) VALUES ('$key','$id');";
$rs = mysql_query($sql);
if(!$rs){
$err .= "An error occured while attempting to add the document to the group (key=$key id=$id).";
}
}
if ($err) return $err;
return $key;
#11
Posted 03 August 2008 - 07:10 PM
#12
Posted 04 August 2008 - 01:54 AM
#13
Posted 04 August 2008 - 09:53 AM
$temp=getIntTableRow(with some convoluted where query to ensure you are collecting the right row)
$key=$temp[0]['id'];
$fields=array($key, $id);
putIntTableRow($fields,'table');
Unless there are API's that return the key of inserted rows, sometimes they are more trouble than they are worth. I too have resorted to direct database queries in cases like the above. Is there an etomite-friendly way of doing what Mike has done using existing API's? If there is, it escapes me.
#14
Posted 04 August 2008 - 10:48 AM
#15
Posted 04 August 2008 - 01:20 PM
$etomite->insertId() and $etomite->affectedRows() come in handy and will work with both internal and external database API functions... Probably another one of those areas that would benefit from a tutorial if I can ever muster up the time...
#16
Posted 05 August 2008 - 09:15 AM
Ralph, on Aug 4 2008, 02:54 AM, said:
#17
Posted 05 August 2008 - 09:22 AM
What about outputting system error messages with a user-defined chunk in cocoon so that admin can style an etomite error message to look like part of the site?- just a thought (and actually waaaaay of topic - sorry).
#18
Posted 05 August 2008 - 09:44 AM
Edited by mikef, 05 August 2008 - 09:48 AM.
#19
Posted 05 August 2008 - 12:48 PM
#20
Posted 05 August 2008 - 03:02 PM
Ralph, on Aug 5 2008, 01:48 PM, said:
Quote
New post started at http://www.etomite.c...?showtopic=7990
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











