5
0
Fork 0
mirror of https://github.com/WenPai-org/wenpai.org.git synced 2025-08-17 14:11:09 +08:00

feat: 添加单个插件/主题的导入命令

This commit is contained in:
耗子 2024-11-15 02:03:51 +08:00
parent 7195bc9932
commit 5c2032d7b4
No known key found for this signature in database
GPG key ID: C964D7226D045DAA
4 changed files with 82 additions and 7 deletions

View file

@ -110,8 +110,12 @@ WHERE status = 'failed';
### 下面是一些可能会使用到的 CLI 命令。
```bash
wp --allow-root --url=wenpai.org/plugins platform wporg_plugins_update force_run
wp --allow-root --url=wenpai.org/themes platform wporg_themes_update force_run
wp --allow-root --url=wenpai.org/plugins platform wporg_plugins_update run
wp --allow-root --url=wenpai.org/themes platform wporg_themes_update run
wp --allow-root --url=wenpai.org/plugins platform wporg_plugins_update run_force
wp --allow-root --url=wenpai.org/themes platform wporg_themes_update run_force
wp --allow-root --url=wenpai.org/plugins platform wporg_plugins_update run_single --slug=woocommerce
wp --allow-root --url=wenpai.org/themes platform wporg_themes_update run_single --slug=twentytwentyfive
wp --allow-root --url=translate.wenpai.org platform translate_import import --type=plugins --slug=woocommerce
wp --allow-root --url=translate.wenpai.org platform translate_import_release release --version=dev --display_version=dev --old_version=dev

View file

@ -199,6 +199,35 @@ class Worker extends WP_CLI_Command {
}
}
public function run_single( $args, $assoc_args ) {
if ( empty( $assoc_args['slug'] ) ) {
WP_CLI::line( '你需要给出要导入的项目 Slug' );
exit;
}
$slugs = [ $assoc_args['slug'] ];
$infos = $this->fetch_remote_plugins( $slugs );
foreach ( $infos as $info ) {
if ( $info === false ) {
WP_CLI::line( '已下架:' . $assoc_args['slug'] );
continue;
}
if ( empty( $info ) ) {
WP_CLI::line( '空数据:' . $assoc_args['slug'] );
continue;
}
try {
$this->update_post( $assoc_args['slug'], $info );
} catch ( Exception $e ) {
WP_CLI::line( '出错:' . $e->getMessage() );
}
}
WP_CLI::line( '搞定!' );
}
/**
* 更新文章
*

View file

@ -28,7 +28,7 @@ class Worker extends WP_CLI_Command {
* 全量更新
* @return void
*/
public function force_run(): void {
public function run_force(): void {
while ( ob_get_level() ) {
ob_end_flush();
}
@ -199,6 +199,35 @@ class Worker extends WP_CLI_Command {
}
}
public function run_single( $args, $assoc_args ) {
if ( empty( $assoc_args['slug'] ) ) {
WP_CLI::line( '你需要给出要导入的项目 Slug' );
exit;
}
$slugs = [ $assoc_args['slug'] ];
$infos = $this->fetch_remote_themes( $slugs );
foreach ( $infos as $info ) {
if ( $info === false ) {
WP_CLI::line( '已下架:' . $assoc_args['slug'] );
continue;
}
if ( empty( $info ) ) {
WP_CLI::line( '空数据:' . $assoc_args['slug'] );
continue;
}
try {
$this->update_post( $assoc_args['slug'], $info );
} catch ( Exception $e ) {
WP_CLI::line( '出错:' . $e->getMessage() );
}
}
WP_CLI::line( '搞定!' );
}
/**
* 更新文章
*

View file

@ -8,6 +8,7 @@ use Platform\Chinese_Format\Chinese_Format;
use Platform\Logger\Logger;
use Translation_Entry;
use WordPressdotorg\GlotPress\TranslationSuggestions\Translation_Memory_Client;
use WP_CLI;
use WP_Error;
use WPorg_GP_Project_Stats;
use function Platform\Translate\WPOrgTranslateImport\create_project;
@ -42,9 +43,17 @@ class Project {
set_time_limit( 3600 );
ignore_user_abort( true );
}
$route = new GP_Route;
$wporg_url = sprintf( 'https://translate.wordpress.org/locale/zh-cn/default/wp-%s/%s/', $type, $slug );
$data = get_web_page_contents( $wporg_url );
if ( is_wp_error( $data ) || false === $data ) {
if ( is_wp_error( $data ) ) {
if ( 'cli' !== PHP_SAPI ) {
$route->redirect_with_error( $data->get_error_message() );
} else {
WP_CLI::line( $data->get_error_message() );
}
return false;
}
@ -54,8 +63,6 @@ class Project {
$sub_projects = self::get_theme_sub_project( $slug );
}
$route = new GP_Route;
if ( is_wp_error( $sub_projects ) ) {
Logger::error( Logger::TRANSLATE, '获取子项目详情失败', array(
'slug' => $slug,
@ -64,7 +71,9 @@ class Project {
) );
if ( 'cli' !== PHP_SAPI ) {
$route->redirect_with_error( '获取子项目详情失败' );
$route->redirect_with_error( '获取子项目详情失败:' . $sub_projects->get_error_message() );
} else {
WP_CLI::line( '获取子项目详情失败:' . $sub_projects->get_error_message() );
}
return false;
@ -107,6 +116,10 @@ class Project {
'error' => $data->get_error_message(),
) );
if ( 'cli' == PHP_SAPI ) {
WP_CLI::line( '请求翻译文件失败:' . $data->get_error_message() );
}
continue;
}