Ning Developer Network

Skidoo

Updating the Content Store

Hi - I'm trying to update a content object in the Ning content store, but for some reason it's not working.

Here's the code I'm trying to use to update the content object ...

function write_data ($user, $quiz_name, $correct_answers, $incorrect_answers, $answer_list) {        $contentQuery = XN_Query::create('Content');
        $contentQuery->filter('type','eic','My Quiz');
$contentQuery->filter('owner');
$contentQuery->filter('my->uid','=',$user);
$results = $contentQuery->execute();

foreach($results as $resultsdata) {
}

$contentObject = XN_Content::load($resultsdata->id);

$contentObject->my->correct += $correct_answers;
$contentObject->my->incorrect += $incorrect_answers;

if ($quiz_name == "test_quiz") {
$contentObject->my->test_quiz = 'true';
$contentObject->my->test_quiz_answers = $answer_list;
}

if ($quiz_name == "test_quiz2") {
$contentObject->my->test_quiz2 = 'true';
$contentObject->my->test_quiz2_answers = $answer_list;
}

$contentObject->save();
}

When I run the code above, I get the following error message ...

Fatal error:  Uncaught exception 'XN_Exception' with message 'Failed to save content:XN_Content:
  id [922007:MyQuiz389:1104]
createdDate [2008-03-25T16:07:29.753Z]
updatedDate [2008-03-25T16:07:29.753Z]
type [My Quiz]
title [My Quiz Data]
description []
tagCount [0]
contributorName []
ownerName [Sun Cafe]
ownerUrl [suncafe]
isPrivate [true]
my attributes [
[922007:MyQuiz389:1104-uid-1] uid : 661053464 : string
[922007:MyQuiz389:1104-correct-2] correct : 1 : number
[922007:MyQuiz389:1104-incorrect-3] incorrect : 1 : number
[922007:MyQuiz389:1104-test_quiz2-4] test_quiz2 : true : string
[922007:MyQuiz389:1104-test_quiz2_answers-5] test_quiz2_answers : 1,2 : string
]
<?xml version='1.0' encoding='UTF-8'?>
<errors>
<error code="unknown">Submitted content is incompatible with its shape (My Quiz) in app suncafe. [Attribute my.correct of shape My Quiz has type string which is not compatible with value type Long, Attribute my.incorrect of shape in /php/includes/XN/XN/Exception.php on line 56

Anyone have any ideas as to why I'm getting this error message. Thanks in advance for the help.

Tags: content, error, php, store

Reply to This

Replies to This Discussion

Hi Skidoo,

For the my->correct attribute the content store is expecting a string, but you're giving it a numeric value; it may be expecting a string because in previous saves of this type (incidentally it's a good idea to avoid creating types with spaces in the name) you saved a string value there, or you didn't specify a type, so it defaulted to string. You should be able to update the value for that attribute (and my->incorrect) to be strings prior to saving. Also, if you've retrieved a content item via a query, you don't need to load it a second time before performing any updates on it.

Thanks,
Phil

Reply to This

Hi Phil,

I have this problem right now, but your explanation doesn't make much sense to me... We just did a 3.1.5 merge. The BlogPost W_Model has an attribute $lastViewedOn which is an XN_Attribute::DATE type. When I create new blog post, it won't save (see log excerpt below). So this is the first time the content is being created and saved with a date type, not a string, so why is it failing? Thanks!

[06-Jun-2008 15:55:17] BlogController::action_create: Failed to save content:
XN_Content:
id []
createdDate []
updatedDate []
type [BlogPost]
title [Last Viewed When?]
description [Cras placerat. Curabitur lobortis. ]
tagCount [0]
contributorName []
ownerName [FohBoh Test]
ownerUrl []
isPrivate [false]
my attributes [
[-1] xg_profiles_commentCount : 0 : number
[-1] xg_profiles_commentToApproveCount : 0 : number
[-1] mozzle : profiles : string
[-1] publishTime : 2008-06-06T15:55:17Z : date
[-1] allowComments : Y : string
[-1] words : 0 : number
[-1] topTags : : string
[-1] viewCount : 0 : number
[-1] popularityCount : 0 : number
[-1] lastViewedOn : 2008-06-06T15:55:17Z : date
[-1] format : 2.2 : string
[-1] searchText : Last Viewed When? Cras placerat. Curabitur lobortis. : string
[-1] publishStatus : publish : string
[-1] visibility : all : string
[-1] categoryId : 1474782:Category:2481 : string
[-1] publishWhen : now : string
[-1] addCommentPermission : all : string
]


Submitted content is incompatible with its shape (BlogPost) in app fohbohtest. [Attribute my.lastViewedOn of shape BlogPost has type string which is not compatible with value type Date]

#0 /php/includes/XN/XN/REST.php(202): XN_REST->doRequest('POST', '/content', '
#2 /php/includes/XN/XN/Content.php(308): XN_Content->_saveProper(false, false)
#3 [internal function]: XN_Content->save()
#4 /php/includes/XN/WWF/lib/W_Content.php(264): call_user_func_array(Array, Array)
#5 [internal function]: W_Content->__call('save', Array)
#6 /apps/fohbohtest/widgets/profiles/controllers/BlogController.php(279): W_Content->save()
#7 [internal function]: Profiles_BlogController->action_create()

Reply to This

Hi Ted,

It's likely that a content object was created at some point that didn't specify that that attribute type should be a date, so it defaulted to a string and created the current problem.

You should be able to fix it like this:
$shape = XN_Shape::load('BlogPost');
if ($shape) {
$shape->setAttribute('my.lastViewedOn', 'date');
$shape->save();
}

Thanks,
Phil

Reply to This

RSS

Documentation & Tips

© 2008   Created by Ning Developer Admin

Badges  |  Report an Issue  |  Privacy  |  Terms of Service