3xw/attachment-third-party

此包的最新版本(3.0.2)没有可用的许可信息。

CakePHP 工具插件

安装: 5

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 0

公开问题: 0

类型:cakephp-plugin

3.0.2 2019-05-16 10:16 UTC

This package is auto-updated.

Last update: 2024-09-16 22:25:39 UTC


README

第三方附件(YouTube等)。是插件 3xw/attachment 的子项目。

安装

您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。

安装 composer 包的推荐方法是

composer require 3xw/attachment-third-party

添加队列任务

在 Application.php 文件中激活插件

// Queue
$this->addPlugin('Queue');

然后迁移数据库

bin/cake migrations migrate -p Queue

谷歌

安装

安装谷歌库

composer require google/apiclient:^2.0

保护

忽略您的谷歌私有设置。在 .gitignore 文件中添加以下内容

/config/google/*

OAuth

  • 在这里 选择/创建一个谷歌项目
  • 在库菜单中激活 YouTube 库
  • 创建并下载 OAuth 客户端(类型为 "Other"),将其放置在 config/google/credentials.json 中

用法

准备

当使用附件时,设置事件监听器,可以是

  • 全局在 config/attachment.php 中
return [
	'Attachment' => [

		//...

		'listeners' => [
			'beforeSave' => [
				'Attachment\Listener\ModifyTypeListener' => [
					'type' => 'transit',
					'subtype' => 'youtube', // or other third party name
				]
			],
		]

		//...

	]
];
  • 在任意模板中特别设置
$this->Attachment->buildIndex([
	'actions' => ['add','edit','delete','view'],
	'types' =>['image/jpeg','image/png','embed/youtube','embed/vimeo','video/quicktime','transit/youtube'],
	'listeners' => [
		'beforeSave' => [
			'Attachment\Listener\ModifyTypeListener' => [
				'type' => 'transit',
				'subtype' => 'youtube',
			]
		],
	]
])

移动文件

通过创建 cron 任务,插件将查找类型为 "transit" 的附件,并为每个附件创建相关移动类的队列任务。

bin/cake queue add CreateTransitStack & bin/cake queue runworker