| 1 |
<?php |
| 2 |
namespace BetterLinks\Tools\Migration; |
| 3 |
if ( ! defined( 'ABSPATH' ) ) { exit; } |
| 4 |
|
| 5 |
use BetterLinks\Interfaces\ImportOneClickInterface; |
| 6 |
|
| 7 |
class TAOneClick extends BaseCSV implements ImportOneClickInterface |
| 8 |
{ |
| 9 |
public function run_importer($data) |
| 10 |
{ |
| 11 |
$message = []; |
| 12 |
if (is_array($data) && count($data) > 0) { |
| 13 |
foreach ($data as $item) { |
| 14 |
if (!empty($item['link_title']) && !empty($item['short_url'])) { |
| 15 |
$link_id = \BetterLinks\Helper::insert_link($item); |
| 16 |
if ($link_id) { |
| 17 |
if (!empty($item['keywords'])) { |
| 18 |
$this->insert_keywords($link_id, $item['keywords'], ['limit' => $item['limit']]); |
| 19 |
} |
| 20 |
$terms = empty($item['terms']) ? ['uncategorized'] : $item['terms']; |
| 21 |
$terms_ids = \BetterLinks\Helper::insert_category_terms($terms); |
| 22 |
if (count($terms_ids) > 0) { |
| 23 |
foreach ($terms_ids as $term_id) { |
| 24 |
\BetterLinks\Helper::insert_terms_relationships($term_id, $link_id); |
| 25 |
} |
| 26 |
} |
| 27 |
$message[] = 'Imported Successfully "' . $item['short_url'] . '"'; |
| 28 |
} else { |
| 29 |
$message[] = 'Imported Failed "' . $item['short_url'] . '" already exists.'; |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
return [ |
| 35 |
'links' => $message |
| 36 |
]; |
| 37 |
} |
| 38 |
} |
| 39 |
|