-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixtures.php
executable file
·78 lines (60 loc) · 2.06 KB
/
fixtures.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
require __DIR__.'/vendor/autoload.php';
use ActivityStreams\ActionInterface;
use ActivityStreams\DataResolver\DataResolverProvider;
use Blog\ActivityStreams\ActionManager;
use Blog\ActivityStreams\DataResolver\UserResolver;
use Blog\ActivityStreams\DataResolver\PostResolver;
use Blog\ActivityStreams\DataResolver\CategoryResolver;
use Blog\Model\User;
use Blog\Model\UserQuery;
use Blog\Model\Category;
use Blog\Model\CategoryQuery;
use Blog\Model\Post;
use Blog\Model\PostQuery;
// init Propel
Propel::init(__DIR__.'/config/conf/Blog-conf.php');
function writeln($object)
{
echo sprintf('Created "%s" with id "%s"', get_class($object), $object->getId()).PHP_EOL;
}
// create data resolver provider instance
$provider = new DataResolverProvider();
$provider->addDataResolver(new UserResolver());
$provider->addDataResolver(new PostResolver());
$provider->addDataResolver(new CategoryResolver());
// create action manager instance
$actionManager = new ActionManager($provider);
// create fixtures
foreach (array('john', 'tobi', 'adam') as $id => $username) {
$user = new User();
$user->setUsername($username);
// save user
$user->save();
writeln($user);
}
foreach (array('Web', 'Life', 'Open Source', 'PHP') as $value) {
$category = new Category();
$category->setName($value);
$user = UserQuery::create()->findPk(rand(1,3));
$category->setUser($user);
// save category
$category->save();
// create action
$actionManager->createAction($category->getUser(), Category::CREATE_CATEGORY, $category);
writeln($category);
}
for ($i=0; $i<= 20; $i++) {
$post = new Post();
$post->setTitle('Post title '. $i);
$post->setBody('Post body '. $i);
$user = UserQuery::create()->findPk(rand(1,3));
$post->setUser($user);
$category = $user = CategoryQuery::create()->findPk(rand(1,9));
$post->setCategory($category);
// create post
$post->save();
// create action
$actionManager->createAction($post->getUser(), Post::CREATE_POST, $post, $post->getCategory());
writeln($post);
}