Esempio n. 1
0
 public function run()
 {
     $faker = Faker::create();
     $log = new Stream('php://stdout');
     $log->info('Start ' . __CLASS__);
     /** @var Phalcon\Db\AdapterInterface $database */
     $database = $this->getDI()->get('db');
     $database->begin();
     for ($i = 0; $i <= self::USERS_TOTAL; $i++) {
         $user = new Users();
         $user->username = $faker->userName;
         $user->email = $faker->email;
         $user->timezone = $faker->timezone;
         $user->moderator = rand(0, 1) ? 'Y' : 'N';
         $user->karma = mt_rand(10, 20000);
         $user->vote = mt_rand(10, 200);
         $user->votePoint = mt_rand(10, 100);
         $user->gender = rand(0, 1) ? 1 : 2;
         //1-male, 2-female
         $user->passwd = 'todolate';
         $user->status = 1;
         //1-active, 2-pending
         $user->theme = 'D';
         if (!$user->save()) {
             var_dump($users->getMessages());
             $database->rollback();
             die;
         }
         $log->info('users: ' . $user->getUsername());
     }
 }
Esempio n. 2
0
 public function run()
 {
     $faker = Faker::create();
     $log = new Stream('php://stdout');
     $log->info('Start ' . __CLASS__);
     /** @var Phalcon\Db\AdapterInterface $database */
     $database = $this->getDI()->get('db');
     $userIds = Users::find(['columns' => 'id'])->toArray();
     $database->begin();
     for ($i = 0; $i <= self::POSTS_TOTAL; $i++) {
         $title = $faker->company;
         $userRandId = array_rand($userIds);
         $posts = new Posts();
         $posts->usersId = $userIds[$userRandId]['id'];
         $posts->type = rand(0, 1) ? 'questions' : 'tips';
         $posts->title = $title;
         $posts->slug = \Phalcon\Tag::friendlyTitle($title);
         $posts->numberViews = rand(5, 100);
         $posts->numberReply = rand(0, 20);
         $posts->content = $faker->text;
         $posts->sticked = 'N';
         $posts->status = 'A';
         $posts->locked = 'N';
         $posts->deleted = 0;
         $posts->acceptedAnswer = 'N';
         if (!$posts->save()) {
             var_dump($posts->getMessages());
             $database->rollback();
             die;
         }
         $log->info('posts: ' . $posts->getTitle());
     }
 }
Esempio n. 3
0
 public function run()
 {
     $faker = Faker::create();
     $log = new Stream('php://stdout');
     $log->info('Start ' . __CLASS__);
     /** @var Phalcon\Db\AdapterInterface $database */
     $database = $this->getDI()->get('db');
     $database->begin();
     for ($i = 0; $i <= self::TAGS_TOTAL; $i++) {
         $title = $faker->company;
         $description = $faker->text;
         $tags = new Tags();
         $tags->name = $title;
         $tags->slug = \Phalcon\Tag::friendlyTitle($title);
         $tags->numberPosts = 0;
         $tags->noBounty = 'N';
         $tags->noDigest = 'N';
         $tags->description = $description;
         if (!$tags->save()) {
             var_dump($tags->getMessages());
             $database->rollback();
             die;
         }
         $log->info('tags: ' . $tags->getName());
     }
 }
Esempio n. 4
0
    public function run()
    {
        $log = new Stream('php://stdout');
        /** @var Config $config */
        $config = Di::getDefault()->getShared('config');
        $expireDate = new DateTime('now', new DateTimeZone('UTC'));
        $expireDate->modify('+1 month');
        $baseUrl = rtrim($config->get('site')->url, '/');
        $content = <<<EOL
User-agent: *
Allow: /
Sitemap: {$baseUrl}/sitemap.xml
EOL;
        $adapter = new Local(dirname(dirname(__FILE__)) . '/public');
        $filesystem = new Filesystem($adapter);
        if ($filesystem->has('robots.txt')) {
            $result = $filesystem->update('robots.txt', $content);
        } else {
            $result = $filesystem->write('robots.txt', $content);
        }
        if ($result) {
            $log->info('The robots.txt was successfully updated');
        } else {
            $log->error('Failed to update the robots.txt file');
        }
    }
Esempio n. 5
0
 public function run()
 {
     $log = new Stream('php://stdout');
     /** @var Config $config */
     $config = Di::getDefault()->getShared('config');
     $expireDate = new DateTime('now', new DateTimeZone('UTC'));
     $expireDate->modify('+1 day');
     $sitemap = new DOMDocument("1.0", "UTF-8");
     $sitemap->formatOutput = true;
     $urlset = $sitemap->createElement('urlset');
     $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     $urlset->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $baseUrl = $config->get('site')->url;
     $url = $sitemap->createElement('url');
     $url->appendChild($sitemap->createElement('loc', $baseUrl));
     $url->appendChild($sitemap->createElement('changefreq', 'daily'));
     $url->appendChild($sitemap->createElement('priority', '1.0'));
     $urlset->appendChild($url);
     $karmaSql = 'number_views + ' . '((IF(votes_up IS NOT NULL, votes_up, 0) - IF(votes_down IS NOT NULL, votes_down, 0)) * 4) + ' . 'number_replies';
     $parametersPosts = ['conditions' => 'deleted != 1', 'columns' => "id, slug, modified_at, {$karmaSql} AS karma", 'order' => 'karma DESC'];
     $posts = Posts::find($parametersPosts);
     $parametersKarma = ['column' => $karmaSql, 'conditions' => 'deleted != 1'];
     $karma = Posts::maximum($parametersKarma);
     $modifiedAt = new DateTime('now', new DateTimeZone('UTC'));
     foreach ($posts as $post) {
         $modifiedAt->setTimestamp($post->modified_at);
         $postKarma = $post->karma / ($karma + 100);
         $url = $sitemap->createElement('url');
         $href = trim($baseUrl, '/') . '/discussion/' . $post->id . '/' . $post->slug;
         $url->appendChild($sitemap->createElement('loc', $href));
         $valuePriority = $postKarma > 0.7 ? sprintf("%0.1f", $postKarma) : sprintf("%0.1f", $postKarma + 0.25);
         $url->appendChild($sitemap->createElement('priority', $valuePriority));
         $url->appendChild($sitemap->createElement('lastmod', $modifiedAt->format('Y-m-d\\TH:i:s\\Z')));
         $urlset->appendChild($url);
     }
     $sitemap->appendChild($urlset);
     $adapter = new Local(dirname(dirname(__FILE__)) . '/public');
     $filesystem = new Filesystem($adapter);
     if ($filesystem->has('sitemap.xml')) {
         $result = $filesystem->update('sitemap.xml', $sitemap->saveXML() . PHP_EOL);
     } else {
         $result = $filesystem->write('sitemap.xml', $sitemap->saveXML() . PHP_EOL);
     }
     if ($result) {
         $log->info('The sitemap.xml was successfully updated');
     } else {
         $log->error('Failed to update the sitemap.xml file');
     }
 }
Esempio n. 6
0
 public function run()
 {
     $faker = Faker::create();
     $log = new Stream('php://stdout');
     $log->info('Start ' . __CLASS__);
     /** @var Phalcon\Db\AdapterInterface $database */
     $database = $this->getDI()->get('db');
     $database->begin();
     $postsId = Posts::find(['columns' => 'id'])->toArray();
     $tagsId = Tags::find(['columns' => 'id'])->toArray();
     for ($i = 0; $i <= self::POSTS_TAGS_TOTAL; $i++) {
         $postRandId = array_rand($postsId);
         $tagsRandId = array_rand($tagsId);
         $postTag = new PostsTags();
         $postTag->postsId = $postsId[$postRandId]['id'];
         $postTag->tagsId = $tagsId[$tagsRandId]['id'];
         if (!$postTag->save()) {
             var_dump($tags->getMessages());
             $database->rollback();
             die;
         }
         $log->info('Posts<->Tags ' . $postTag->getPostsId() . '<->' . $postTag->getTagsId());
     }
 }
Esempio n. 7
0
*/
use Phosphorum\Models\Users;
use Phosphorum\Models\Posts;
use Phosphorum\Models\PostsReplies;
use Phosphorum\Models\PostsPollOptions;
use Phosphorum\Models\Categories;
use Phalcon\Logger\Adapter\Stream;
use Phalcon\Tag;
use Faker\Factory as Faker;
/**
 * This script generates random posts
 */
require 'cli-bootstrap.php';
$faker = Faker::create();
$log = new Stream('php://stdout');
$log->info('Start');
/** @var Phalcon\Db\AdapterInterface $database */
$database = $di->getShared('db');
$database->begin();
for ($i = 0; $i <= 20; $i++) {
    $title = $faker->company;
    $category = new Categories();
    $category->name = $title;
    $category->description = $faker->sentence;
    $category->slug = Tag::friendlyTitle($title);
    $category->number_posts = 0;
    $category->no_bounty = 'N';
    $category->no_digest = 'N';
    if (!$category->save()) {
        $database->rollback();
        die(join(PHP_EOL, $category->getMessages()));