Example #1
0
 protected function process()
 {
     $data = $this->preparse_data();
     $data = $this->parse_data($data);
     $save = Request::from(['path' => Operation::encode("{$this->module}/save")], [$_SERVER]);
     #
     # override form
     #
     $core->events->attach(function (Operation\GetFormEvent $event, SaveOperation $operation) use($save) {
         if ($event->request !== $save) {
             return;
         }
         $event->form = new Form();
     });
     /*
     $siteid = $core->site_id;
     $keys = $core->models['nodes']->select('nid')->filter_by_siteid($siteid)->all(\PDO::FETCH_COLUMN);
     
     if ($keys)
     {
     	$core->models['nodes']->where([ 'nid' => $keys ])->delete();
     	$core->models['pages']->where([ 'nid' => $keys ])->delete();
     	$core->models['pages/contents']->where([ 'pageid' => $keys ])->delete();
     }
     */
     $this->import($data, $save);
     $this->response->message = "Records were successfuly imported.";
     return true;
 }
 public static function on_node_save(Event $event, \Icybee\Modules\Nodes\SaveOperation $operation)
 {
     global $core;
     $params =& $event->request->params;
     $nid = $event->rc['key'];
     if (empty($params['nodes_attachments'])) {
         return;
     }
     $model = $core->models['nodes.attachments'];
     $files_model = $core->models['files'];
     $images_model = $core->models['images'];
     $root = \ICanBoogie\DOCUMENT_ROOT;
     $repository = $core->config['repository.temp'] . '/';
     $weight = 0;
     $attached_fileids = array();
     foreach ($params['nodes_attachments'] as $attached_params) {
         if (isset($attached_params['file'])) {
             #
             # create
             #
             $path = $repository . $attached_params['file'];
             $attached_params['path'] = $path;
             $attached_params['is_online'] = true;
             if (getimagesize($root . $path)) {
                 $fileid = \Icybee\Modules\Images\Image::from($attached_params + array(Node::SITEID => $core->site_id, Node::CONSTRUCTOR => 'images'))->save();
             } else {
                 $fileid = \Icybee\Modules\Files\File::from($attached_params + array(Node::SITEID => $core->site_id, Node::CONSTRUCTOR => 'files'))->save();
             }
             if (!$fileid) {
                 $operation->errors[] = new FormattedString('Unable to save file: {0}', array($attached_params));
                 continue;
             }
             $model->save(array('nodeid' => $nid, 'fileid' => $fileid, 'title' => $attached_params['title'], 'weight' => $weight));
             $attached_fileids[] = $fileid;
         } else {
             if (isset($attached_params['fileid'])) {
                 $fileid = $attached_params['fileid'];
                 if ($attached_params['title'] == '!delete') {
                     $file = $files_model[$fileid];
                     $delete_request = Request::from(array('path' => "/api/{$file->constructor}/{$fileid}/delete"));
                     $delete_request->post();
                     continue;
                 } else {
                     if ($attached_params['title'] == '!remove') {
                         continue;
                     }
                 }
                 $model->execute('UPDATE {self} SET title = ?, weight = ? WHERE nodeid = ? AND fileid = ?', array($attached_params['title'], $weight, $nid, $fileid));
                 $attached_fileids[] = $fileid;
             }
         }
         $weight++;
     }
     #
     # we remove the link to unspecified files.
     #
     $model->execute('DELETE FROM {self} WHERE nodeid = ?' . ($attached_fileids ? ' AND fileid NOT IN(' . implode(',', $attached_fileids) . ')' : ''), array($nid));
 }
 public function test_process()
 {
     $request = Request::from(['is_post' => true, 'request_params' => [Operation::DESTINATION => 'nodes', Operation::NAME => 'save', 'title' => "My Example"]]);
     $operation = new FakeSaveOperation();
     $response = $operation($request);
     $record = $operation->record;
     $this->assertEmpty($record->uid);
     $this->assertEquals(1, $record->siteid);
     $this->assertNotEmpty($record->uuid);
     $this->assertEquals("My Example", $record->title);
     $this->assertEquals("my-example", $record->slug);
     $this->assertEquals("nodes", $record->constructor);
     $this->assertEmpty($record->is_online);
     $this->assertEmpty($record->nativeid);
     $this->assertEquals(DateTime::now()->utc, $record->created_at);
     $this->assertEquals(DateTime::now()->utc, $record->updated_at);
 }
Example #4
0
 /**
  * Clears the `core.modules`, `core.configs` and `core.catalogs` caches.
  */
 public static function clear_modules_cache()
 {
     Request::from(Operation::encode('cache/core.modules/clear'))->post();
     Request::from(Operation::encode('cache/core.configs/clear'))->post();
     Request::from(Operation::encode('cache/core.catalogs/clear'))->post();
 }
Example #5
0
 public static function on_authentication_required_rescue(\ICanBoogie\Exception\RescueEvent $event, \ICanBoogie\AuthenticationRequired $target)
 {
     $event->response = Request::from('/signin')->get();
     $event->response->status = $target->getCode();
 }
Example #6
0
 protected function action_signout()
 {
     return Request::from('/api/users/sign-out')->post();
 }
 /**
  * A new nonce request can only be granted if the previous one has expired.
  *
  * @depends test_request
  * @expectedException ICanBoogie\PermissionRequired
  */
 public function test_multiple_request()
 {
     $request = Request::from(array('request_params' => array('email' => '*****@*****.**')));
     $operation = new NonceLoginRequestOperation();
     $response = $operation($request);
 }
 public function test_request()
 {
     global $core;
     $ticket = self::$ticket;
     $ticket->expire_at = '+1 hour';
     $ticket->save();
     $request = Request::from(self::$route->format(self::$ticket));
     $response = $request();
     $this->assertTrue($response->is_successful);
     $this->assertEquals('/admin/profile', $response->location);
     $this->assertNotNull($core->user);
     $this->assertEquals(1, $core->user_id);
     // the ticket for the user must be destroyed.
     $ticket = $core->models['users.noncelogin']->filter_by_uid($ticket->uid)->one;
     $this->assertFalse($ticket);
 }
Example #9
0
 /**
  * Revokes the cache.
  */
 public static function revoke()
 {
     Request::from(Operation::encode('cache/icybee.views/clear'))->post();
 }