Exemple #1
0
 protected function import(array $data, Request $request)
 {
     foreach ($data as $nid => $node) {
         $request->params = (array) $node;
         $response = $request->post();
         $this->keys_translations[$nid] = $response->rc['key'];
     }
 }
 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));
 }
Exemple #3
0
 /**
  * Forwards dispatching to another router.
  *
  * @param Route $route
  *
  * @return Response|mixed
  */
 protected function forward_to_route(Route $route)
 {
     $route->pattern->match($this->request->uri, $captured);
     $request = $this->request->with(['path_params' => $captured]);
     $request->context->route = $route;
     $controller = $route->controller;
     if (!is_callable($controller)) {
         $controller = new $controller();
     }
     return $controller($request);
 }
 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);
 }
Exemple #5
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();
 }
 /**
  * Trying to rescue a NotFound HEAD request using GET instead.
  *
  * @param Request $request
  *
  * @return Response
  */
 private function handle_head(Request $request)
 {
     $response = $this->handle($request->with([Request::OPTION_IS_GET => true]));
     if ($response->content_length === null && !$response->body instanceof \Closure) {
         try {
             $response->content_length = strlen((string) $response->body);
         } catch (\Exception $e) {
             #
             # It's not that bad if we can't obtain the length of the body.
             #
         }
     }
     return $response;
 }
Exemple #7
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();
 }
Exemple #8
0
 protected function action_signout()
 {
     return Request::from('/api/users/sign-out')->post();
 }
Exemple #9
0
 /**
  * Returns the current request.
  *
  * @param Core $app
  *
  * @return Request
  */
 public static function core_get_request(Core $app)
 {
     return Request::get_current_request() ?: $app->initial_request;
 }
 /**
  * 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);
 }
 /**
  * Revokes the cache.
  */
 public static function revoke()
 {
     Request::from(Operation::encode('cache/icybee.views/clear'))->post();
 }