css
1 year ago
js
1 year ago
class-videopress-attachment-metadata.php
2 years ago
class.jetpack-videopress.php
1 year ago
class.videopress-cli.php
2 years ago
class.videopress-edit-attachment.php
3 years ago
class.videopress-gutenberg.php
1 year ago
class.videopress-options.php
2 years ago
class.videopress-player.php
1 year ago
class.videopress-scheduler.php
4 years ago
class.videopress-video.php
1 year ago
class.videopress-xmlrpc.php
2 years ago
editor-media-view.php
2 years ago
shortcode.php
1 year ago
videopress-admin-rtl.css
1 year ago
videopress-admin-rtl.min.css
1 year ago
videopress-admin.css
1 year ago
videopress-admin.min.css
1 year ago
class.videopress-cli.php
192 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName |
| 2 | /** |
| 3 | * VideoPress CLI |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 9 | |
| 10 | /** |
| 11 | * VideoPress command line utilities. |
| 12 | */ |
| 13 | class VideoPress_CLI extends WP_CLI_Command { |
| 14 | /** |
| 15 | * Import a VideoPress Video |
| 16 | * |
| 17 | * ## OPTIONS |
| 18 | * |
| 19 | * <guid>: Import the video with the specified guid |
| 20 | * |
| 21 | * ## EXAMPLES |
| 22 | * |
| 23 | * wp videopress import kUJmAcSf |
| 24 | * |
| 25 | * @param array $args CLI arguments. |
| 26 | */ |
| 27 | public function import( $args ) { |
| 28 | $guid = $args[0]; |
| 29 | $attachment_id = create_local_media_library_for_videopress_guid( $guid ); |
| 30 | if ( $attachment_id && ! is_wp_error( $attachment_id ) ) { |
| 31 | /* translators: %d: attachment id */ |
| 32 | WP_CLI::success( sprintf( __( 'The video has been imported as Attachment ID %d', 'jetpack' ), $attachment_id ) ); |
| 33 | } else { |
| 34 | WP_CLI::error( __( 'An error has been encountered.', 'jetpack' ) ); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Manually runs the job to cleanup videos from the media library that failed during the upload process. |
| 40 | * |
| 41 | * ## EXAMPLES |
| 42 | * |
| 43 | * wp videopress cleanup_videos |
| 44 | */ |
| 45 | public function cleanup_videos() { |
| 46 | $num_cleaned = videopress_cleanup_media_library(); |
| 47 | |
| 48 | /* translators: %d: number of videos cleaned */ |
| 49 | WP_CLI::success( sprintf( _n( 'Cleaned up %d video.', 'Cleaned up a total of %d videos.', $num_cleaned, 'jetpack' ), $num_cleaned ) ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * List out all of the crons that can be run. |
| 54 | * |
| 55 | * ## EXAMPLES |
| 56 | * |
| 57 | * wp videopress list_crons |
| 58 | */ |
| 59 | public function list_crons() { |
| 60 | |
| 61 | $scheduler = VideoPress_Scheduler::init(); |
| 62 | $crons = $scheduler->get_crons(); |
| 63 | $crons_count = is_countable( $crons ) ? count( $crons ) : 0; |
| 64 | |
| 65 | $schedules = wp_get_schedules(); |
| 66 | |
| 67 | if ( $crons_count === 0 ) { |
| 68 | WP_CLI::success( __( 'Found no available cron jobs.', 'jetpack' ) ); |
| 69 | |
| 70 | } else { |
| 71 | /* translators: %d is the number of crons */ |
| 72 | WP_CLI::success( sprintf( _n( 'Found %d available cron job.', 'Found %d available cron jobs.', $crons_count, 'jetpack' ), $crons_count ) ); |
| 73 | } |
| 74 | |
| 75 | foreach ( $crons as $cron_name => $cron ) { |
| 76 | $interval = isset( $schedules[ $cron['interval'] ]['display'] ) ? $schedules[ $cron['interval'] ]['display'] : $cron['interval']; |
| 77 | $runs_next = $scheduler->check_cron( $cron_name ); |
| 78 | $status = $runs_next ? sprintf( 'Scheduled - Runs Next at %s GMT', gmdate( 'Y-m-d H:i:s', $runs_next ) ) : 'Not Scheduled'; |
| 79 | |
| 80 | WP_CLI::log( 'Name: ' . $cron_name ); |
| 81 | WP_CLI::log( 'Method: ' . $cron['method'] ); |
| 82 | WP_CLI::log( 'Interval: ' . $interval ); |
| 83 | WP_CLI::log( 'Status: ' . $status ); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Checks for the current status of a cron job. |
| 89 | * |
| 90 | * ## OPTIONS |
| 91 | * |
| 92 | * <cron_name>: The name of the cron job to check |
| 93 | * |
| 94 | * ## EXAMPLES |
| 95 | * |
| 96 | * wp videopress cron_status cleanup |
| 97 | * |
| 98 | * @param array $args CLI args. |
| 99 | */ |
| 100 | public function cron_status( $args ) { |
| 101 | |
| 102 | if ( ! isset( $args[0] ) ) { |
| 103 | return WP_CLI::error( __( 'You need to provide the name of the cronjob to schedule.', 'jetpack' ) ); |
| 104 | } |
| 105 | |
| 106 | $scheduler = VideoPress_Scheduler::init(); |
| 107 | |
| 108 | if ( ! $scheduler->is_cron_valid( $args[0] ) ) { |
| 109 | /* translators: name of a cron job */ |
| 110 | WP_CLI::error( sprintf( __( 'There is no cron named %s.', 'jetpack' ), $args[0] ) ); |
| 111 | } |
| 112 | |
| 113 | $time = $scheduler->check_cron( $args[0] ); |
| 114 | |
| 115 | if ( ! $time ) { |
| 116 | WP_CLI::success( __( 'The cron is not scheduled to run.', 'jetpack' ) ); |
| 117 | |
| 118 | } else { |
| 119 | /* translators: date/time */ |
| 120 | WP_CLI::success( sprintf( __( 'Cron will run at: %s GMT', 'jetpack' ), gmdate( 'Y-m-d H:i:s', $time ) ) ); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Actives the given cron job |
| 126 | * |
| 127 | * ## OPTIONS |
| 128 | * |
| 129 | * <cron_name>: The name of the cron job to check |
| 130 | * |
| 131 | * ## EXAMPLES |
| 132 | * |
| 133 | * wp videopress activate_cron cleanup |
| 134 | * |
| 135 | * @param array $args CLI args. |
| 136 | */ |
| 137 | public function activate_cron( $args ) { |
| 138 | |
| 139 | if ( ! isset( $args[0] ) ) { |
| 140 | WP_CLI::error( __( 'You need to provide the name of the cronjob to schedule.', 'jetpack' ) ); |
| 141 | } |
| 142 | |
| 143 | $scheduler = VideoPress_Scheduler::init(); |
| 144 | |
| 145 | if ( ! $scheduler->is_cron_valid( $args[0] ) ) { |
| 146 | /* translators: name of a cron job */ |
| 147 | WP_CLI::error( sprintf( __( 'There is no cron named %s.', 'jetpack' ), $args[0] ) ); |
| 148 | } |
| 149 | |
| 150 | $scheduler->activate_cron( $args[0] ); |
| 151 | |
| 152 | /* translators: name of a cron job */ |
| 153 | WP_CLI::success( sprintf( __( 'The cron named `%s` was scheduled.', 'jetpack' ), $args[0] ) ); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Actives the given cron job |
| 158 | * |
| 159 | * ## OPTIONS |
| 160 | * |
| 161 | * <cron_name>: The name of the cron job to check |
| 162 | * |
| 163 | * ## EXAMPLES |
| 164 | * |
| 165 | * wp videopress deactivate_cron cleanup |
| 166 | * |
| 167 | * @param array $args CLI args. |
| 168 | */ |
| 169 | public function deactivate_cron( $args ) { |
| 170 | |
| 171 | if ( ! isset( $args[0] ) ) { |
| 172 | WP_CLI::error( __( 'You need to provide the name of the cronjob to schedule.', 'jetpack' ) ); |
| 173 | } |
| 174 | |
| 175 | $scheduler = VideoPress_Scheduler::init(); |
| 176 | |
| 177 | if ( ! $scheduler->is_cron_valid( $args[0] ) ) { |
| 178 | /* translators: name of a cron job */ |
| 179 | WP_CLI::error( sprintf( __( 'There is no cron named %s.', 'jetpack' ), $args[0] ) ); |
| 180 | } |
| 181 | |
| 182 | $scheduler->deactivate_cron( $args[0] ); |
| 183 | |
| 184 | /* translators: name of a cron job */ |
| 185 | WP_CLI::success( sprintf( __( 'The cron named `%s` was removed from the schedule.', 'jetpack' ), $args[0] ) ); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | // @phan-suppress-next-line PhanUndeclaredFunctionInCallable -- https://github.com/phan/phan/issues/4763 |
| 190 | WP_CLI::add_command( 'videopress', 'VideoPress_CLI' ); |
| 191 | } |
| 192 |