Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • AdjustNode
  • ConfigOperation
  • DeleteBlock
  • DeleteOperation
  • EditBlock
  • ExportBlock
  • ExportOperation
  • Helpers
  • Hooks
  • ImportOperation
  • ManageBlock
  • Model
  • Module
  • Node
  • OfflineOperation
  • OnlineOperation
  • PopNode
  • QueryOperationOperation
  • SaveOperation
  • TitleSlugCombo
  • Update20131208
  • Update20140405
  • ViewProvider

Functions

  • slugize
  1 <?php
  2 
  3 /*
  4  * This file is part of the Icybee package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Icybee\Modules\Nodes;
 13 
 14 use ICanBoogie\Events;
 15 use ICanBoogie\HTTP\Request;
 16 use ICanBoogie\Operation;
 17 
 18 use Brickrouge\Form;
 19 
 20 class ImportOperation extends Operation
 21 {
 22     protected $keys_translations = [];
 23 
 24     protected function get_controls()
 25     {
 26         return [
 27 
 28             self::CONTROL_PERMISSION => Module::PERMISSION_ADMINISTER
 29 
 30         ] + parent::get_controls();
 31     }
 32 
 33     protected function validate(\ICanboogie\Errors $errors)
 34     {
 35         return true;
 36     }
 37 
 38     protected function process()
 39     {
 40         $data = $this->preparse_data();
 41         $data = $this->parse_data($data);
 42 
 43         $save = Request::from([
 44 
 45             'path' => Operation::encode("{$this->module}/save")
 46 
 47         ], [ $_SERVER ] );
 48 
 49         #
 50         # override form
 51         #
 52 
 53         $core->events->attach(function(Operation\GetFormEvent $event, SaveOperation $operation) use($save) {
 54 
 55             if ($event->request !== $save)
 56             {
 57                 return;
 58             }
 59 
 60             $event->form = new Form();
 61 
 62         });
 63 
 64         /*
 65         $siteid = $core->site_id;
 66         $keys = $core->models['nodes']->select('nid')->filter_by_siteid($siteid)->all(\PDO::FETCH_COLUMN);
 67 
 68         if ($keys)
 69         {
 70             $core->models['nodes']->where([ 'nid' => $keys ])->delete();
 71             $core->models['pages']->where([ 'nid' => $keys ])->delete();
 72             $core->models['pages/contents']->where([ 'pageid' => $keys ])->delete();
 73         }
 74         */
 75 
 76         $this->import($data, $save);
 77 
 78         $this->response->message = "Records were successfuly imported.";
 79 
 80         return true;
 81     }
 82 
 83     protected function preparse_data()
 84     {
 85         $json = file_get_contents(\ICanBoogie\DOCUMENT_ROOT . 'export.json');
 86         $data = json_decode($json);
 87 
 88         if (!$data)
 89         {
 90             throw new \ICanBoogie\Exception("Failed to decode JSON: !json", [ 'json' => $json ]);
 91         }
 92 
 93         return (array) $data->rc;
 94     }
 95 
 96     protected function parse_data(array $data)
 97     {
 98         global $core;
 99 
100         $site = $core->site;
101         $siteid = $site->siteid;
102         $language = $site->language;
103 
104         $is_translating = true;
105 
106         foreach ($data as $nid => $node)
107         {
108             $node->siteid = $siteid;
109 
110             if ($is_translating)
111             {
112                 $node->nativeid = $nid;
113             }
114 
115             $node->language = $language;
116         }
117 
118         return $data;
119     }
120 
121     protected function import(array $data, Request $request)
122     {
123         foreach ($data as $nid => $node)
124         {
125             $request->params = (array) $node;
126 
127             $response = $request->post();
128 
129             $this->keys_translations[$nid] = $response->rc['key'];
130         }
131     }
132 }
Autodoc API documentation generated by ApiGen 2.8.0