classes/Tools/BatchTool.php
protected function getImportBatch($page, $forceImages = false) {
        $total = 0;
        $pages = 1;
        $shouldRun = false;
        $fromSelection = false;

        if (isset($_POST['selection'])) {
            $postIds = $_POST['selection'];
            $total = count($postIds);
            $shouldRun = true;
        } else {
            $postIds = get_site_transient($this->batchPrefix().'_post_selection');
            if (!empty($postIds)) {
                delete_site_transient($this->batchPrefix().'_post_selection');
                $total = count($postIds);
                $shouldRun = true;
                $fromSelection = true;
            } else {
                $args = [
                    'post_type' => 'attachment',
                    'post_status' => 'inherit',
                    'posts_per_page' => 100,
                    'fields' => 'ids',
                    'paged' => $page
                ];

                if ($page == -1) {
                    unset($args['posts_per_page']);
                    unset($args['paged']);
                    $args['nopaging'] = true;
                }

                $args = $this->filterPostArgs($args);

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

                $query = new \WP_Query($args);

                $postIds = $query->posts;

                $total = (int)$query->found_posts;
                $pages = $query->max_num_pages;
            }
        }


        $posts = [];
        foreach($postIds as $post) {
            $thumb = wp_get_attachment_image_src($post, 'thumbnail', true);

            $thumbUrl = null;
            $icon = false;
            if (!empty($thumb)) {
                $thumbUrl = $thumb[0];
                $icon = (($thumb[1] != 150) && ($thumb[2] != 150));
            }

            $posts[] = [
                'id' => $post,
                'title' => pathinfo(get_attached_file($post), PATHINFO_BASENAME),
                'thumb' => $thumbUrl,
                'icon' => $icon
            ];
        }

        return [
            'posts' =>$posts,
            'total' => $total,
            'pages' => $pages,
            'shouldRun' => $shouldRun,
            'fromSelection' => $fromSelection
        ];
    }
protected function getImportBatch($page, $forceImages = false) {
        $total = 0;
        $pages = 1;
        $shouldRun = false;
        $fromSelection = false;

        if (isset($_POST['selection'])) {
            $postIds = $_POST['selection'];
            $total = count($postIds);
            $shouldRun = true;
        } else {
            $postIds = get_site_transient($this->batchPrefix().'_post_selection');
            if (!empty($postIds)) {
                delete_site_transient($this->batchPrefix().'_post_selection');
                $total = count($postIds);
                $shouldRun = true;
                $fromSelection = true;
            } else {
                $args = [
                    'post_type' => 'attachment',
                    'post_status' => 'inherit',
                    'posts_per_page' => 100,
                    'fields' => 'ids',
                    'paged' => $page
                ];

                if ($page == -1) {
                    unset($args['posts_per_page']);
                    unset($args['paged']);
                    $args['nopaging'] = true;
                }

                $args = $this->filterPostArgs($args);

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

                $query = new \WP_Query($args);

                $postIds = $query->posts;

                $total = (int)$query->found_posts;
                $pages = $query->max_num_pages;
            }
        }


        $posts = [];
        foreach($postIds as $post) {
            $thumb = wp_get_attachment_image_src($post, 'thumbnail', true);

            $thumbUrl = null;
            $icon = false;
            if (!empty($thumb)) {
                $thumbUrl = $thumb[0];
                $icon = (($thumb[1] != 150) && ($thumb[2] != 150));
            }

            $posts[] = [
                'id' => $post,
                'title' => pathinfo(get_attached_file($post), PATHINFO_BASENAME),
                'thumb' => $thumbUrl,
                'icon' => $icon
            ];
        }

        return [
            'posts' =>$posts,
            'total' => $total,
            'pages' => $pages,
            'shouldRun' => $shouldRun,
            'fromSelection' => $fromSelection
        ];
    }
protected function getImportBatch ( $ page , $ forceImages = false ) { $ total = 0 ; $ pages = 1 ; $ shouldRun = false ; $ fromSelection = false ; if ( isset ( $ _POST [ 'selection' ] ) ) { $ postIds = $ _POST [ 'selection' ] ; $ total = count ( $ postIds ) ; $ shouldRun = true ; } else { $ postIds = get_site_transient ( $ this -> batchPrefix ( ) . '_post_selection' ) ; if ( ! empty ( $ postIds ) ) { delete_site_transient ( $ this -> batchPrefix ( ) . '_post_selection' ) ; $ total = count ( $ postIds ) ; $ shouldRun = true ; $ fromSelection = true ; } else { $ args = [ 'post_type' => 'attachment' , 'post_status' => 'inherit' , 'posts_per_page' => 100 , 'fields' => 'ids' , 'paged' => $ page ] ; if ( $ page == - 1 ) { unset ( $ args [ 'posts_per_page' ] ) ; unset ( $ args [ 'paged' ] ) ; $ args [ 'nopaging' ] = true ; } $ args = $ this -> filterPostArgs ( $ args ) ; if ( $ forceImages || ! StorageSettings :: uploadDocuments ( ) ) { $ args [ 'post_mime_type' ] = 'image' ; } $ query = new \ WP_Query ( $ args ) ; $ postIds = $ query -> posts ; $ total = ( int ) $ query -> found_posts ; $ pages = $ query -> max_num_pages ; } } $ posts = [ ] ; foreach ( $ postIds as $ post ) { $ thumb = wp_get_attachment_image_src ( $ post , 'thumbnail' , true ) ; $ thumbUrl = null ; $ icon = false ; if ( ! empty ( $ thumb ) ) { $ thumbUrl = $ thumb [ 0 ] ; $ icon = ( ( $ thumb [ 1 ] != 150 ) && ( $ thumb [ 2 ] != 150 ) ) ; } $ posts [ ] = [ 'id' => $ post , 'title' => pathinfo ( get_attached_file ( $ post ) , PATHINFO_BASENAME ) , 'thumb' => $ thumbUrl , 'icon' => $ icon ] ; } return [ 'posts' => $ posts , 'total' => $ total , 'pages' => $ pages , 'shouldRun' => $ shouldRun , 'fromSelection' => $ fromSelection ] ; }
Gets the post data to process for this batch.  Data is paged to minimize memory usage.
@param $page
@param bool $forceImages
@return array
Gets the post data to process for this batch . Data is paged to minimize memory usage .