Permalink
Browse files

Fix Author_ID value for SymWrite when Author is not available

  • Loading branch information...
1 parent 2631159 commit 2cd17eff6b3e10eedd0045d9bd889e227498613c @brendo committed with psychoticmeow Mar 19, 2010
Showing with 24 additions and 24 deletions.
  1. +1 −1 lib/class.symquery.php
  2. +23 −23 lib/class.symwrite.php
View
2 lib/class.symquery.php
@@ -394,7 +394,7 @@ public function __construct($section) {
}
}
- class SymQueryExeption extends Exception {
+ class SymQueryExecption extends Exception {
}
View
46 lib/class.symwrite.php
@@ -1,85 +1,85 @@
<?php
-
+
function SymWrite($section) {
return new SymWrite($section);
}
-
+
class SymWrite extends SymQuery {
protected $filterable = false;
protected $writes = array();
-
+
public function set($field, $data) {
$this->writes[] = self::buildFieldWriter($field, $data, $this->section);
-
+
return $this;
}
-
+
public function write() {
$author = SymQuery::$symphony->Author;
$section = $this->section->get('object');
$entry = SymQuery::$em->create();
$entry_data = array();
-
+
// Build default entry data:
$entry->set('section_id', $section->get('id'));
- $entry->set('author_id', $author->get('id'));
+ $entry->set('author_id', (!is_object($author)) ? 0 : $author->get('id'));
$entry->set('creation_date', DateTimeObj::get('Y-m-d H:i:s'));
$entry->set('creation_date_gmt', DateTimeObj::getGMT('Y-m-d H:i:s'));
-
+
foreach ($this->writes as $write) {
$field = $write->get('object');
$field_data = $write->get('data');
-
+
if ($field == SymQuery::SYSTEM_ID) {
$entry->set('id', $field_data);
}
-
+
else if ($field instanceof Field) {
$field_handle = $field->get('element_name');
-
+
$entry_data[$field_handle] = $field_data;
}
}
-
+
if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($entry_data, $errors)) {
$error = new SymWriteException('Unable to validate entry.');
$error->setValidationErrors($errors);
-
+
throw $error;
}
-
+
if (__ENTRY_OK__ != $entry->setDataFromPost($entry_data, $error)) {
throw new SymQueryException(sprintf(
'Unable to save entry: %s', $error
));
}
-
+
$entry->commit();
-
+
return $entry;
}
}
-
- class SymWriteException extends SymQueryExeption {
+
+ class SymWriteException extends SymQueryExecption {
protected $validation_errors = array();
-
+
/**
* Get an array containing any validation errors
- *
+ *
* @return Array
*/
public function getValidationErrors() {
return $this->validation_errors;
}
-
+
/**
* Set the array of validation errors
- *
+ *
* @param $errors Array
*/
public function setValidationErrors(Array $errors) {
$this->validation_errors = $errors;
}
}
-
+
?>

0 comments on commit 2cd17ef

Please sign in to comment.