classes/CLI/Storage/StorageCommands.php
public function import($args, $assoc_args) {
	    $this->debugMode = (\WP_CLI::get_config('debug') == 'mediacloud');

	    // Force the logger to initialize
	    Logger::instance();

		/** @var StorageTool $storageTool */
		$storageTool = ToolsManager::instance()->tools['storage'];

		if (!$storageTool || !$storageTool->enabled()) {
			Command::Error('Storage tool is not enabled in Media Cloud or the settings are incorrect.');
			return;
		}

		$postArgs = [
			'post_type' => 'attachment',
			'post_status' => 'inherit',
			'nopaging' => true,
			'fields' => 'ids',
		];

		if(!StorageSettings::uploadDocuments()) {
			$args['post_mime_type'] = 'image';
		}

		$query = new \WP_Query($postArgs);

		if($query->post_count > 0) {
		    BatchManager::instance()->reset('storage');

            BatchManager::instance()->setStatus('storage', true);
            BatchManager::instance()->setTotalCount('storage', $query->post_count);
            BatchManager::instance()->setCurrent('storage', 1);
            BatchManager::instance()->setShouldCancel('storage', false);

			Command::Info("Total posts found: %Y{$query->post_count}.", true);

			$pd = new DefaultProgressDelegate();

			for($i = 1; $i <= $query->post_count; $i++) {
				$postId = $query->posts[$i - 1];
				$upload_file = get_attached_file($postId);
				$fileName = basename($upload_file);

                BatchManager::instance()->setCurrentFile('storage', $fileName);
                BatchManager::instance()->setCurrent('storage', $i);

				Command::Info("%w[%C{$i}%w of %C{$query->post_count}%w] %NImporting %Y$fileName%N %w(Post ID %N$postId%w)%N ... ", $this->debugMode);
				$storageTool->processImport($i - 1, $postId, $pd);
				if (!$this->debugMode) {
                    Command::Info("%YDone%N.", true);
                }
			}

			BatchManager::instance()->reset('storage');
		}
	}
public function import($args, $assoc_args) {
	    $this->debugMode = (\WP_CLI::get_config('debug') == 'mediacloud');

	    // Force the logger to initialize
	    Logger::instance();

		/** @var StorageTool $storageTool */
		$storageTool = ToolsManager::instance()->tools['storage'];

		if (!$storageTool || !$storageTool->enabled()) {
			Command::Error('Storage tool is not enabled in Media Cloud or the settings are incorrect.');
			return;
		}

		$postArgs = [
			'post_type' => 'attachment',
			'post_status' => 'inherit',
			'nopaging' => true,
			'fields' => 'ids',
		];

		if(!StorageSettings::uploadDocuments()) {
			$args['post_mime_type'] = 'image';
		}

		$query = new \WP_Query($postArgs);

		if($query->post_count > 0) {
		    BatchManager::instance()->reset('storage');

            BatchManager::instance()->setStatus('storage', true);
            BatchManager::instance()->setTotalCount('storage', $query->post_count);
            BatchManager::instance()->setCurrent('storage', 1);
            BatchManager::instance()->setShouldCancel('storage', false);

			Command::Info("Total posts found: %Y{$query->post_count}.", true);

			$pd = new DefaultProgressDelegate();

			for($i = 1; $i <= $query->post_count; $i++) {
				$postId = $query->posts[$i - 1];
				$upload_file = get_attached_file($postId);
				$fileName = basename($upload_file);

                BatchManager::instance()->setCurrentFile('storage', $fileName);
                BatchManager::instance()->setCurrent('storage', $i);

				Command::Info("%w[%C{$i}%w of %C{$query->post_count}%w] %NImporting %Y$fileName%N %w(Post ID %N$postId%w)%N ... ", $this->debugMode);
				$storageTool->processImport($i - 1, $postId, $pd);
				if (!$this->debugMode) {
                    Command::Info("%YDone%N.", true);
                }
			}

			BatchManager::instance()->reset('storage');
		}
	}
public function import ( $ args , $ assoc_args ) { $ this -> debugMode = ( \ WP_CLI :: get_config ( 'debug' ) == 'mediacloud' ) ; // Force the logger to initialize Logger :: instance ( ) ; /** @var StorageTool $storageTool */ $ storageTool = ToolsManager :: instance ( ) -> tools [ 'storage' ] ; if ( ! $ storageTool || ! $ storageTool -> enabled ( ) ) { Command :: Error ( 'Storage tool is not enabled in Media Cloud or the settings are incorrect.' ) ; return ; } $ postArgs = [ 'post_type' => 'attachment' , 'post_status' => 'inherit' , 'nopaging' => true , 'fields' => 'ids' , ] ; if ( ! StorageSettings :: uploadDocuments ( ) ) { $ args [ 'post_mime_type' ] = 'image' ; } $ query = new \ WP_Query ( $ postArgs ) ; if ( $ query -> post_count > 0 ) { BatchManager :: instance ( ) -> reset ( 'storage' ) ; BatchManager :: instance ( ) -> setStatus ( 'storage' , true ) ; BatchManager :: instance ( ) -> setTotalCount ( 'storage' , $ query -> post_count ) ; BatchManager :: instance ( ) -> setCurrent ( 'storage' , 1 ) ; BatchManager :: instance ( ) -> setShouldCancel ( 'storage' , false ) ; Command :: Info ( "Total posts found: %Y{$query->post_count}." , true ) ; $ pd = new DefaultProgressDelegate ( ) ; for ( $ i = 1 ; $ i <= $ query -> post_count ; $ i ++ ) { $ postId = $ query -> posts [ $ i - 1 ] ; $ upload_file = get_attached_file ( $ postId ) ; $ fileName = basename ( $ upload_file ) ; BatchManager :: instance ( ) -> setCurrentFile ( 'storage' , $ fileName ) ; BatchManager :: instance ( ) -> setCurrent ( 'storage' , $ i ) ; Command :: Info ( "%w[%C{$i}%w of %C{$query->post_count}%w] %NImporting %Y$fileName%N %w(Post ID %N$postId%w)%N ... " , $ this -> debugMode ) ; $ storageTool -> processImport ( $ i - 1 , $ postId , $ pd ) ; if ( ! $ this -> debugMode ) { Command :: Info ( "%YDone%N." , true ) ; } } BatchManager :: instance ( ) -> reset ( 'storage' ) ; } }
Imports the media library to the cloud.

@when after_wp_load

@param $args
@param $assoc_args
Imports the media library to the cloud .