1. Backup data table to csv file (using datagrip)
catalog_product_entity.csv
entity_id,sku,quickbooks_entity,quickbooks_sync_token
86304,15100_SVBKB_9,30,0
86307,15100_SVBKB_8,31,0
86310,15100_SVBKB_7,32,0
86313,15100_SVBKB_6,33,0
86316,15100_SVBKB_12,34,0
86319,15100_SVBKB_11,35,0
2. Put catalog_product_entity.csv to magento/pub/catalog_product_entity.csv
3. Create file restore.php in magento/pub/restore.php
<?php
use \Magento\Framework\App\Bootstrap;
include('../app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
// Get connection
$host = '127.0.0.1';
$dbname = 'dddd';
$username = 'aaaa';
$password = 'ssss';
$tableName = 'catalog_product_entity';
$filePath = 'catalog_product_entity.csv';
// Connect to MariaDB
$conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Open the CSV file
$csvFile = fopen($filePath, 'r');
fgetcsv($csvFile);
$sql = "UPDATE $tableName SET quickbooks_entity = ?, quickbooks_sync_token = ? WHERE entity_id = ?";
$stmt = $conn->prepare($sql);
while (($data = fgetcsv($csvFile, null, ',')) !== FALSE) {
/**
* entity_id,sku,quickbooks_entity,quickbooks_sync_token
* 0: entity_id
* 2: quickbooks_entity
* 3: quickbooks_sync_token
*/
$entity_id = $data[0];
$quickbooks_entity = $data[2];
$quickbooks_sync_token = $data[3];
if ($entity_id && $quickbooks_entity) {
$stmt->execute([$quickbooks_entity, $quickbooks_sync_token, $entity_id]);
echo "Updated entity_id = $entity_id, quickbooks_entity = $quickbooks_entity, quickbooks_sync_token = $quickbooks_sync_token \n";
}
}
fclose($csvFile);
$conn = null;
echo "\n\n $filePath imported successfully!";