public function batch_save($content_items)
{
$chunk_size = $this->batch_size;
$content_items = $this->map_array($content_items);
if (!empty($content_items)) {
$copy = array();
foreach ($content_items as $content_item) {
if (!isset($content_item['parent'])) {
if ($this->import_to_page_id != false) {
$content_item['parent'] = $this->import_to_page_id;
}
}
$copy[] = $content_item;
}
$content_items = $copy;
}
$chunks_folder = $this->get_chunks_location();
$index_file = $chunks_folder . 'index.php';
if (!is_dir($chunks_folder)) {
mkdir_recursive($chunks_folder);
@touch($index_file);
}
if (!is_writable($chunks_folder)) {
return array('error' => 'Import folder is not writable!');
}
$chunks = array_chunk($content_items, $chunk_size, true);
$i = 0;
if (!empty($chunks)) {
foreach ($chunks as $chunk) {
$chunk_data = serialize($chunk);
$pad = str_pad($i, 8, '0', STR_PAD_LEFT);
$file_name = 'import_chunk_' . $pad;
$file_location = $chunks_folder . $file_name;
if (!is_file($file_location)) {
file_put_contents($file_location, $chunk_data);
}
$i++;
}
}
return array('success' => count($content_items) . ' items are scheduled for import');
}