This object is in archive! 

The addition of a new response from a cron

Archived Jan L. 12 years ago

Hello,

I want to add a new answer/comment from a php function which is executed from a cron. I tried to use

$data = Array (

"title" => "test",

"slug" => "test",

"content" => "test",

"type" => "question",

"file" => Array ( "file_0_" => "1.txt", "file_1_" => "2.txt" ),

"tags" => "",

"status" => "",

"is_active" => 1,

"is_private" => 1,

"created_at" => "2012-04-26 07:00:40",

"created_by_id" => 6008,

"search_index" => ""

);

$activeResponse = new System_Model_Response();

$activeResponse->save($data);but they are cannot be added in the data base,can you help me to write a function wich accomplish this thing?

Best Answer
photo

Take a look on this example:


$user = Singular_Loader::get('System_Model_DbTable_Users')->findById(5717);


if ( !($user instanceof System_Model_User) ) return;


Singular_Runtime::store('loggedUser', $user);

$data = Array(

"title" => "test213qqqq",

"slug" => "test",

"content" => "test",

"type" => "question",

"created_by_id" => $user->id,

"tags" => "",

"is_private" => 1,

);


$response = new System_Model_Response();

$response->save($data);


$file = new Files_Model_File();

$data = array(

'object_id' => $response->id,

'object' => $response->type,

'name' => 'test1.png',

'location' => '1234567', //file name on filesystem

);

$file->save($data);


It will require to modify following files (will be incorporated in next release):


system/model/response.php (line 94) to:

$this->subscribe($this->created_by_id);


system/model/DbTable/Logs.php (lines 71 - 73):

$loggedUser = Singular_Runtime::extract('loggedUser');$data['created_by_name'] = $loggedUser->full_name;$data['created_by_email'] = $loggedUser->email;


Important - cron script must be launched with curl.

Replies (2)

photo
1

Take a look on this example:


$user = Singular_Loader::get('System_Model_DbTable_Users')->findById(5717);


if ( !($user instanceof System_Model_User) ) return;


Singular_Runtime::store('loggedUser', $user);

$data = Array(

"title" => "test213qqqq",

"slug" => "test",

"content" => "test",

"type" => "question",

"created_by_id" => $user->id,

"tags" => "",

"is_private" => 1,

);


$response = new System_Model_Response();

$response->save($data);


$file = new Files_Model_File();

$data = array(

'object_id' => $response->id,

'object' => $response->type,

'name' => 'test1.png',

'location' => '1234567', //file name on filesystem

);

$file->save($data);


It will require to modify following files (will be incorporated in next release):


system/model/response.php (line 94) to:

$this->subscribe($this->created_by_id);


system/model/DbTable/Logs.php (lines 71 - 73):

$loggedUser = Singular_Runtime::extract('loggedUser');$data['created_by_name'] = $loggedUser->full_name;$data['created_by_email'] = $loggedUser->email;


Important - cron script must be launched with curl.

photo
1

In UR 2.0 we'll have API available, so it would be much easier to implement such features.

Replies have been locked on this page!