Inheritance: extends Jarves\Model\Base\Domain
Beispiel #1
0
 public function installDemoData()
 {
     \Jarves\Model\DomainQuery::create()->deleteAll();
     \Jarves\Model\NodeQuery::create()->deleteAll();
     \Jarves\Model\ContentQuery::create()->deleteAll();
     \Jarves\Model\AppLockQuery::create()->deleteAll();
     \Jarves\Model\AclQuery::create()->deleteAll();
     $domainName = $this->getDomain();
     $domainName = explode(':', $domainName)[0];
     $domain = new Domain();
     $domain->setDomain($domainName);
     $path = $this->getPath();
     $domain->setPath($path);
     $domain->setTitleFormat('%title% | Node title - My Website - change me under domain settings.');
     $domain->setMaster(1);
     $domain->setLang('en');
     $domain->setResourceCompression(0);
     $domain->setTheme('jarvesDemoTheme');
     $domain->setSearchIndexKey(md5(time() . '-' . rand()));
     $domain->save();
     $root = new Node();
     $root->setDomainId($domain->getId());
     $root->makeRoot();
     $root->setTitle('root');
     $root->setUrn('');
     $root->save();
     //setup live workspace
     WorkspaceQuery::create()->deleteAll();
     $workspace = new Workspace();
     $workspace->setTitle('LIVE');
     $workspace->setCreated(time());
     $workspace->save();
     $id = $workspace->getId();
     if ($id != 1) {
         WorkspaceQuery::create()->filterById($id)->update(array('Id' => 1));
     }
     $defaultLayout = 'default';
     $defaultContentTemplate = 'JarvesBundle:Default:content.html.twig';
     $Nodes = array(array(0, 'Blog', $defaultLayout, 'home', '', array('1' => array(array('text', 'Jarves cms has been installed!', $defaultContentTemplate, '<p>Jarves cms has been installed correctly.</p><p>&nbsp;</p><p><a href="http://www.jarves.io">Jarves cms Website</a></p><p>&nbsp;</p><p>&nbsp;</p><p>Go to <a href="jarves">administration</a> to manage your new website.</p><p>&nbsp;</p><p><strong>Default login:</strong></p><p><strong><br /></strong></p><p style="padding-left: 10px;">Username: admin</p><p style="padding-left: 10px;">Password: admin</p>'), array('plugin', '', $defaultContentTemplate, '{"bundle":"JarvesPublicationBundle","plugin":"listing","options":{"itemsPerPage":10,"maxPages":10,"detailPage":"","template":"default.html.twig","categoryId":[],"enableRss":false}}')), '2' => array(array('plugin', '» CATEGORIES', $defaultContentTemplate, '{"bundle":"JarvesPublicationBundle","plugin":"categoryList","options":{"listNode":"1","template":"default.html.twig","category_rsn":[]}}'))), array(array(1, 'Article', $defaultLayout, 'article', '', array(), array(), 0))), array(0, 'Links', $defaultLayout, 'links', '', array('1' => array(array('text', 'Links', $defaultContentTemplate, 'Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi.')), '2' => array(array('text', '» About', $defaultContentTemplate, 'hoho'))), array(array(1, 'Jarves cms Official Website', $defaultLayout, 'www-jarves-org', 'http://www.jarves.io/'), array(1, 'Jarves cms Documentation', $defaultLayout, 'docu-jarves-org', 'http://docu.jarves.io/'), array(1, 'Jarves cms Extensions', $defaultLayout, 'www-jarves-org-extensions', 'http://www.jarves.io/extensions'))), array(0, 'About me', $defaultLayout, 'about-me', '', array('1' => array(array('text', 'About me', $defaultContentTemplate, 'Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi.')), '2' => array(array('text', 'Hi, my Name is', $defaultContentTemplate, 'John Doe and I\'m a creative dude living in Springfield. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt...'))), array(array(0, 'Sublink 1', $defaultLayout, 'sublink-1', '', array('1' => array(array('text', 'Sublink 1', $defaultContentTemplate, 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.')))), array(0, 'Sublink 2', $defaultLayout, 'sublink-2', '', array('1' => array(array('text', 'Sublink 1', $defaultContentTemplate, 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.<br/><br/><h3>Lorem ...</h3>ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.')))))), array(2, 'Footer Navigation', '', '', '', array(), array(array(0, 'Sitemap', $defaultLayout, 'sitemap', '', array('1' => array(array('plugin', 'Sitemap', $defaultContentTemplate, 'todo')))), array(0, 'Contact', $defaultLayout, 'contact', '', array('1' => array(array('plugin', 'Contact form', $defaultContentTemplate, 'todo')))), array(0, 'Impress', $defaultLayout, 'impress', '', array('1' => array(array('text', 'Impress', $defaultContentTemplate, 'Owner: <b>Name</b><br/>Street, Nr<br/>Country<br/>')))))), array(3, 'Footer text', '', '', '', array('1' => array(array('text', '', $defaultContentTemplate, '<p>&copy; my Node | <a href="http://www.jarves.io/">CMS</a> powered by Jarves cms - simply different</p>'))), array()));
     /*
      * 0: type
      * 1: Title
      * 2: layout
      * 3: url
      * 4: link target
      * 5: contents
      * 6: children
      * 7: visible
      */
     foreach ($Nodes as $Node) {
         $oNode = new Node();
         $oNode->setDomainId($domain->getId());
         $oNode->setType($Node[0]);
         $oNode->setTitle($Node[1]);
         $oNode->setLayout($Node[2]);
         $oNode->setUrn($Node[3]);
         $oNode->insertAsLastChildOf($root);
         if (isset($Node[7])) {
             $oNode->setVisible($Node[7]);
         } else {
             $oNode->setVisible(1);
         }
         $oNode->save();
         if ($Node[4]) {
             $oNode->setLink($Node[4]);
         }
         if ($Node[5]) {
             $this->installContents($oNode, $Node[5]);
         }
         if ($Node[6]) {
             $this->installNodes($oNode, $Node[6]);
         }
     }
     $startNode = NodeQuery::create()->filterByDomainId($domain->getId())->findOneByLft(2);
     $domain->setStartnodeId($startNode->getId());
     $domain->save();
     LanguageQuery::create()->deleteAll();
     $h = fopen(__DIR__ . '/Resources/package/ISO_639-1_codes.csv', 'r');
     if ($h) {
         while (($data = fgetcsv($h, 1000, ",")) !== false) {
             $lang = new Language();
             $lang->setCode($data[0]);
             $lang->setTitle($data[1]);
             $lang->setLangtitle($data[2]);
             $lang->save();
         }
     }
     LanguageQuery::create()->filterByCode('en')->update(array('Visible' => 1));
     //search footer id
     $footerNavi = NodeQuery::create()->findOneByTitle('Footer Navigation');
     $footerText = NodeQuery::create()->findOneByTitle('Footer text');
     $domainThemeProperties = ['footerNavigation' => $footerNavi->getId(), 'footerTray' => $footerText->getId()];
     $domain->setThemeOptions($domainThemeProperties);
     $domain->save();
     SessionQuery::create()->deleteAll();
     UserGroupQuery::create()->deleteAll();
     UserQuery::create()->deleteAll();
     GroupQuery::create()->deleteAll();
     AclQuery::create()->deleteAll();
     $groupGuest = new Group();
     $groupGuest->setName('Guest');
     $groupGuest->setDescription('All anonymous user');
     $groupGuest->save();
     $id = $groupGuest->getId();
     GroupQuery::create()->filterById($id)->update(array('Id' => 0));
     $groupAdmin = new Group();
     $groupAdmin->setName('Admin');
     $groupAdmin->setDescription('Super user');
     $groupAdmin->save();
     $id = $groupAdmin->getId();
     GroupQuery::create()->filterById($id)->update(array('Id' => 1));
     $groupAdmin->setId(1);
     $groupUsers = new Group();
     $groupUsers->setName('Users');
     $groupUsers->setDescription('Registered user');
     $groupUsers->save();
     $admin = new User();
     $admin->setUsername('admin');
     $admin->setFirstName('Admini');
     $admin->setLastName('strator');
     $admin->setEmail('admin@localhost');
     $admin->setActivate(1);
     $encoderFactory = $this->container->get('security.encoder_factory');
     $encoder = $encoderFactory->getEncoder($admin);
     $admin->setPassword($encoder->encodePassword('admin', null));
     $liveWorkspace = WorkspaceQuery::create()->findOneById(1);
     $admin->addWorkspace($liveWorkspace);
     $settings = new \Jarves\Properties(array('userBg' => '/admin/images/userBgs/defaultImages/color-blue.jpg', 'adminLanguage' => 'en'));
     $admin->setSettings($settings);
     $admin->save();
     $id = $admin->getId();
     UserQuery::create()->filterById($id)->update(array('Id' => 1));
     $admin->setId(1);
     $admin->addGroup($groupAdmin);
     $admin->save();
 }
Beispiel #2
0
 protected function exportNode($position, Domain $domain, Node $node, ExportPointer $exportPointer)
 {
     $data = $node->toArray(TableMap::TYPE_CAMELNAME);
     if (!$node->getUrn()) {
         return;
     }
     $path = $node->getUrn();
     $exportPointer->pushPath($path);
     if ($node->getId() === $domain->getStartnodeId()) {
         $domain->setVirtualColumn('startnodePath', $path);
     }
     $nodeData = $this->clearData($data, ['id', 'lft', 'rgt', 'lvl', 'pid', 'urn', 'domainId'], ['type' => 0, 'layout' => 'default', 'visible' => true]);
     $nodeData['sort'] = $position;
     $contents = $node->getContents();
     $contentsData = [];
     foreach ($contents as $content) {
         $contentData = $content->toArray(TableMap::TYPE_CAMELNAME);
         $jsonDecoded = json_decode($contentData['content'], true);
         if (JSON_ERROR_NONE === json_last_error()) {
             $contentData['content'] = $jsonDecoded;
         }
         $contentData = $this->clearData($contentData, ['id', 'nodeId'], ['template' => 'JarvesBundle:Default:content.html.twig', 'type' => 'text']);
         $contentsData[] = $contentData;
     }
     $nodeData['contents'] = $contentsData;
     $exportPointer->addData($nodeData, '.yml');
     foreach ($node->getChildren() as $idx => $child) {
         $this->exportNode($idx, $domain, $child, $exportPointer);
     }
     $exportPointer->popPath();
 }
Beispiel #3
0
 protected function import(InputInterface $input, OutputInterface $output)
 {
     $basePath = 'app/jarves/';
     $openedFiles = [];
     $domains = [];
     $nodes = [];
     $rootNodes = [];
     $ymlParser = new Parser();
     Propel::getWriteConnection('default')->beginTransaction();
     //import files
     $fileReferencesPath = $basePath . '/file_references.yml';
     if (file_exists($fileReferencesPath)) {
         $openedFiles[$fileReferencesPath] = filemtime($fileReferencesPath);
         $fileReferences = $ymlParser->parse(file_get_contents($fileReferencesPath));
         $output->writeln(sprintf('Import %d file references ...', count($fileReferences)));
         FileQuery::create()->deleteAll();
         foreach ($fileReferences as $id => $path) {
             $file = new File();
             $file->setId($id);
             $file->setPath($path);
             $file->save();
         }
     }
     $relativePathBase = $basePath . 'website/';
     $dir = opendir($relativePathBase);
     while ($domainName = readdir($dir)) {
         if ('.' === $domainName || '..' === $domainName || '.yml' === substr($domainName, -4)) {
             continue;
         }
         $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($basePath . 'website/' . $domainName));
         $files = iterator_to_array($files);
         ksort($files);
         $output->writeln(sprintf('Import domain %s ...', $domainName));
         $domain = DomainQuery::create()->findOneByDomain($domainName);
         if (!$domain) {
             $domain = new Domain();
         }
         $ymlPath = $relativePathBase . $domainName . '.yml';
         $domainFromYml = $ymlParser->parse(file_get_contents($ymlPath));
         $openedFiles[$ymlPath] = filemtime($ymlPath);
         $oldData = $domain->toArray(TableMap::TYPE_CAMELNAME);
         $domain->fromArray(array_merge($oldData, $domainFromYml), TableMap::TYPE_CAMELNAME);
         $domain->setStartnodeId(null);
         if (isset($domainFromYml['startnode'])) {
             $domain->setVirtualColumn('startnodePath', $domainFromYml['startnode']);
         }
         $domain->save();
         $domains[$domainName] = $domain;
         NodeQuery::create()->filterByDomain($domain)->delete();
         $rootNode = new Node();
         $rootNode->setTitle('root');
         $rootNode->makeRoot();
         $rootNode->setDomain($domain);
         $rootNode->save();
         $rootNodes[$domainName] = $rootNode;
         $nodes[''] = $rootNode;
         $parentNodeQueue = [];
         /** @var \SplFileInfo $file */
         foreach ($files as $file) {
             if ('.' === $file->getFilename() || '..' === $file->getFilename() || '.yml' !== substr($file->getFilename(), -4)) {
                 continue;
             }
             $path = $file->getPath() . '/' . $file->getFilename();
             $path = substr($path, strlen($relativePathBase . $domainName) + 1);
             if (!$path) {
                 continue;
             }
             $parentPath = '';
             if (false !== strpos($path, '/')) {
                 $parentPath = dirname($path);
             }
             $baseName = substr(basename($path), 0, -4);
             //without .yml
             if ($baseName) {
                 //its a node
                 $node = isset($nodes[$path]) ? $nodes[$path] : new Node();
                 $ymlPath = $relativePathBase . $domainName . '/' . $path;
                 $nodeFromYml = $ymlParser->parse(file_get_contents($ymlPath));
                 $openedFiles[$ymlPath] = filemtime($ymlPath);
                 $node->fromArray($nodeFromYml, TableMap::TYPE_CAMELNAME);
                 $node->setDomain($domain);
                 $urn = $baseName;
                 if (false !== ($dotPos = strpos($baseName, '.'))) {
                     $prefix = substr($baseName, 0, $dotPos);
                     if ($prefix) {
                         $urn = substr($baseName, $dotPos + 1);
                     }
                 }
                 $node->setUrn($urn);
                 $output->writeln(sprintf('Import page %s%s ...', str_repeat('  ', substr_count($path, '/')), $node->getTitle()));
                 $nodes[substr($path, 0, -4)] = $node;
                 $end = isset($parentNodeQueue[$parentPath]) ? count($parentNodeQueue[$parentPath]) : 1;
                 $position = isset($nodeFromYml['sort']) ? $nodeFromYml['sort'] : $end;
                 $parentNodeQueue[$parentPath][$position][] = $node;
                 if (isset($nodeFromYml['contents'])) {
                     foreach ($nodeFromYml['contents'] as $idx => $contentFromYaml) {
                         if (isset($contentFromYaml['content']) && is_array($contentFromYaml['content'])) {
                             $contentFromYaml['content'] = json_encode($contentFromYaml['content']);
                         }
                         $content = new Content();
                         $content->setSort($idx);
                         $content->fromArray($contentFromYaml, TableMap::TYPE_CAMELNAME);
                         $content->setNode($node);
                     }
                     if ($domain->hasVirtualColumn('startnodePath') && substr($path, 0, -4) === $domain->getVirtualColumn('startnodePath')) {
                         $domain->setStartnode($node);
                     }
                 }
             }
         }
         //save queued nodes
         foreach ($parentNodeQueue as $parentPath => $nodesQueue) {
             ksort($nodesQueue);
             //key is sort
             /** @var Node $node */
             foreach ($nodesQueue as $position => $nodesToInsert) {
                 foreach ($nodesToInsert as $node) {
                     $node->insertAsLastChildOf($nodes[$parentPath]);
                     $node->save();
                     //saves Content as well.
                 }
             }
         }
         $domain->save();
     }
     Propel::getWriteConnection('default')->commit();
     $cacher = $this->getContainer()->get('jarves.cache.cacher');
     $cacher->invalidateCache('core');
     return $openedFiles;
 }
Beispiel #4
0
 /**
  * @group test
  */
 public function testPatchDomain()
 {
     $newDomain = new Domain();
     $newDomain->setPath('/');
     $newDomain->setDomain('testDomainName');
     $newDomain->setTheme('defaultTheme');
     $newDomain->save();
     $patched = $this->getObjects()->patch('jarves/domain', $newDomain->getId(), ['domain' => 'testdomain.tld', 'theme' => 'coreLayouts']);
     $this->assertTrue($patched);
     $domain = DomainQuery::create()->findOneById($newDomain->getId());
     $this->assertEquals('testdomain.tld', $domain->getDomain());
     $this->assertEquals('coreLayouts', $domain->getTheme());
     $newDomain->delete();
 }
Beispiel #5
0
 /**
  * @return Domain
  */
 public function getCurrentDomain()
 {
     if (null === $this->domain && $this->getRequest()) {
         $domain = new Domain();
         $domain->setDomain($this->getRequest()->getHost());
         $domain->setPath($this->getRequest()->getBasePath());
         $domain->setMaster(true);
         return $domain;
     }
     return $this->domain;
 }