webplumbr/elastic-blog

基于 Symfony 2 的项目使用的 ElasticSearch 驱动的博客包

v0.7.2 2016-02-29 23:42 UTC

This package is not auto-updated.

Last update: 2024-10-02 09:54:14 UTC


README

如果您正在考虑将您的 WordPress 博客迁移到使用 No-SQL 的平台,甚至开始一个博客平台,那么请尝试这个包。它使用 ElasticSearch 来提供全文搜索功能,并将您的博客文章以及关联的用户、标签、评论存储为 ElasticSearch 中的 JSON 文档。

在开始之前,请阅读以下内容

待办事项

  1. 目前不保留您的 WordPress 类别和页面(这意味着:您的 WordPress 类别和页面不能导入)
  2. 用户密码更改功能
  3. 编写 PHPunit 测试用例

需求

  1. PHP 版本 5.5 或更高
  2. Symfony 2.3 LTS 或更高版本及其默认的供应商包(开箱即用)
  3. ElasticSearch 版本 >= 1.0

演示

从 WordPress 迁移的博客

安装与配置

步骤 1. 将以下包添加到您的 composer.json

require {
  "webplumbr/elastic-blog": "v0.6"
}

步骤 2. 运行以下命令安装包及其依赖项

composer update

步骤 3. 在您的 app/AppKernel.php 文件中注册该包

$bundles[] = new Webplumbr\BlogBundle\WebplumbrBlogBundle();

步骤 4. 编辑 app/config/config.yml 并在 assetic 下添加以下内容

assetic:
    bundles:        [WebplumbrBlogBundle]

步骤 5. 将以下内容添加到 app/config/parameters.yml.dist 文件

    elastic_host: localhost
    elastic_port: 9200
    elastic_index: your_blog_index
    # change the following
    secret: YouBetterChangeThisToSomethingElse
    # this is used as the default password for all users that you might
    # import using your existing Wordpress Blog XML
    default_user_password: '!letmein!'

注意 请记住将 default_user_passwordsecret 参数更改为适合您的值。

运行以下命令获取上述参数

composer install

步骤 6. 将以下内容添加到 app/config/routing.yml 文件

webplumbr_blog:
    resource: "@WebplumbrBlogBundle/Controller/"
    type:     annotation
    prefix:   /

步骤 7. 确保您的 app/config/security.yml 文件与以下内容类似

# To get started with security, check out the documentation:
# https://symfony.com.cn/doc/current/book/security.html
security:
    encoders:
      Symfony\Component\Security\Core\User\User:
        algorithm: bcrypt
        cost: 12
      Webplumbr\BlogBundle\Security\User\ElasticUser:
        algorithm: bcrypt
        cost: 12

    # https://symfony.com.cn/doc/current/book/security.html#where-do-users-come-from-user-providers
    providers:
        chain_provider:
            chain:
                providers: [in_memory, elasticuser]
        in_memory:
            memory:
                users:
                    # generated using: https://www.dailycred.com/article/bcrypt-calculator
                    superman: { password: '$2a$12$7BhgZjRGuSueYLJy1ZNNieSHf2VDdFsvqyG3wajDu2//VSX5gIT3m', roles: 'ROLE_SUPER_ADMIN' }
        elasticuser:
            id: elastic_user_provider

    firewalls:
        # disables authentication for assets and the profiler, adapt it according to your needs
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        main:
            anonymous: ~
            # activate different ways to authenticate

            # http_basic: ~
            # https://symfony.com.cn/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate

            # https://symfony.com.cn/doc/current/cookbook/security/form_login_setup.html
            # reference: http://stackoverflow.com/a/26614055
            form_login:
                login_path: /admin/login
                check_path: /admin/login-check
                default_target_path: /admin/dashboard
                always_use_default_target_path: true
            logout:
                path: /admin/logout
                target: /admin/login

    access_control:
        - { path: ^/admin/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin, roles: [ROLE_ADMIN, ROLE_SUPER_ADMIN] }

步骤 8. 输出所有新安装的资产

app/console assetic:dump
app/console assets:install --symlink

步骤 9. 将以下内容添加到文件 /etc/elasticsearch/elasticsearch.yml

http.max_initial_line_length: 1mb
http.max_content_length: 10mb

步骤 10. 默认超级管理员用户凭据用于首次登录,除非您已在 app/config/security.yml 中将其更改为其他内容。

username: superman
password: !underwear!

步骤 11. 您可以尝试以下操作来打印此包提供的可用路由

app/console router:debug

步骤 12. 登录到管理区域后,通过访问“导入 WordPress 博客”链接来导入您的 WordPress XML。

如果一切顺利,您应该会看到您的 WordPress 博客文章、标签、评论和用户已成功迁移到基于 ElasticSearch 的博客平台。

常见问题解答

如果您有任何问题,请确保您已经检查了以下内容

  1. Elasticsearch 是否已安装并作为服务运行?
  2. Symfony 2 是否有写入 app/cache 和/或 app/logs 文件夹的所需权限?
  3. 您是否已清除 Symfony 2 缓存文件夹?
  4. 是否已满足此包之外的安装依赖项?
  5. 如果您在运行 composer update 时遇到“未找到匹配的包”错误,请将项目根级别 composer.json 的最低稳定性更改为“dev”
  6. 如果您遇到“找不到活动节点”或“空服务器”异常,请确保您已按照步骤 9 进行更改。