$app->config->publicDataDir->remove(true); } cli\line('Dropping existing database..'); $schema->dropDatabase(); $app->em->beginTransaction(); try { cli\line('Creating schema..'); $schema->createSchema($app->em->getMetadataFactory()->getAllMetadata()); cli\line('Creating default user..'); $user = new \Chalk\Core\User(); $user->fromArray(['name' => 'Root', 'emailAddress' => '*****@*****.**', 'passwordPlain' => 'password', 'role' => \Chalk\Core\User::ROLE_DEVELOPER]); $app->em->persist($user); $app->em->flush(); cli\line('Creating default page..'); $page = new \Chalk\Core\Page(); $page->fromArray(['name' => 'Site']); $app->em->persist($page); $app->em->flush(); cli\line('Creating default structures..'); $struct1 = new \Chalk\Core\Structure(); $struct1->fromArray(['name' => 'Primary']); $struct1->root->content = $page; $struct1->root->name = 'Home'; $app->em->persist($struct1); $app->em->flush(); $struct2 = new \Chalk\Core\Structure(); $struct2->fromArray(['name' => 'Secondary']); $app->em->persist($struct2); $app->em->flush(); cli\line('Creating default domain..'); $domain = new \Chalk\Core\Domain();
cli\line('Creating sample data..'); $html = ' <h1>{0}</h1> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo dignissimos explicabo eius autem dolorum, ducimus, possimus sed sint! Perspiciatis praesentium at eum ea molestiae. Aut voluptas alias magni, amet sit.</p> <p>Cumque, earum culpa maxime ex facere eaque, natus mollitia rem quia nam in. Voluptas reiciendis eum a porro ut provident, totam veniam, itaque autem rem deserunt vel in, molestiae nam!</p> <p>Unde doloribus vero quos labore, qui consequatur perspiciatis sit accusantium aut explicabo doloremque error ducimus ipsa nemo exercitationem, omnis dolores earum non tenetur a! Dignissimos delectus cumque nemo voluptate nihil!</p> <p>Iusto a cum esse provident maiores incidunt doloribus voluptate, animi quibusdam molestias. Eveniet ad nemo eius excepturi quisquam repellat officiis distinctio, adipisci cum saepe porro dicta, iure deserunt mollitia nostrum!</p> '; $names = array('name', 'lobortis augue scelerisque mollis.', 'aliquet', 'adipiscing elit.', 'dictum ultricies', 'vel, mauris.', 'accumsan laoreet', 'enim nisl elementum', 'tellus faucibus', 'Donec', 'eleifend. Cras sed', 'ac tellus. Suspendisse', 'egestas. Sed pharetra,', 'magnis', 'mi pede, nonummy', 'per', 'vulputate eu, odio. Phasellus', 'nec ante.', 'Donec dignissim', 'Vivamus euismod urna. Nullam', 'nisl. Quisque fringilla', 'nec,', 'ante. Vivamus non lorem'); shuffle($names); $structs = $app->em('Chalk\\Core\\Structure')->all(['sort' => 'id']); $struct = $structs[0]; $nodes = [$struct->root]; foreach ($names as $name) { $name = ucwords($name); $page = new \Chalk\Core\Page(); $page->fromArray(['name' => $name, 'blocks' => [['name' => 'primary', 'value' => str_replace('{0}', $name, $html)]]]); $app->em->persist($page); $node = new \Chalk\Core\Structure\Node(); $node->content = $page; $node->parent = rand(0, 10) ? $nodes[array_rand($nodes)] : $nodes[0]; $app->em->persist($node); $nodes[] = $node; } $app->em->flush(); cli\line('Comitting to database..'); $app->em->commit(); } catch (Exception $e) { $app->em->rollback(); cli\err('Error: ' . $e->getMessage()); }