Created
August 18, 2017 15:06
-
-
Save aleksandar-babic/bc9a64ac25dbde3c240674ba7ac9d71d to your computer and use it in GitHub Desktop.
mage2 cannot gather stats product
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if($argc == 2){ | |
$db['db_host'] = '127.0.0.1'; | |
$db['db_username'] = 'username'; | |
$db['db_password'] = 'password'; | |
$db['db_databaseName'] = 'db'; | |
$db['db_port'] = '3306'; // This is default MySql port, you can change it if needed | |
foreach ($db as $key => $value) { | |
define(strtoupper($key), $value); | |
} | |
$connection = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASENAME, DB_PORT); | |
if($connection) | |
echo "Connected to database.\n"; | |
else | |
echo "Error connecting to database.\n"; | |
$sku = $argv[1]; | |
$hitResults = []; | |
$i = 0; | |
$query = "SELECT * FROM catalog_product_entity ent LEFT JOIN catalog_product_entity_media_gallery_value val ON ( val.entity_id = ent.entity_id ) LEFT JOIN catalog_product_entity_media_gallery gal ON ( gal.value_id = val.value_id ) WHERE ent.sku = '{$sku}' "; | |
$getResults = mysqli_query($connection,$query); | |
while($row = mysqli_fetch_assoc($getResults)){ | |
$hitResults[$i] = $row['value_id']; | |
$i++; | |
} | |
foreach ($hitResults as $imgValue) { | |
$query = "DELETE FROM catalog_product_entity_media_gallery WHERE value_id = '{$imgValue}'"; | |
$deleteImgValue = mysqli_query($connection,$query); | |
if($deleteImgValue){ | |
echo "value_id {$imgValue} for {$sku} deleted.\n"; | |
} else { | |
echo "Error deleting value_id {$imgValue} for {$sku} \n"; | |
} | |
} | |
} else { | |
die("Fatal error. You have to pass product sku as parameter\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment