Inital commit

This commit is contained in:
2020-11-19 15:36:28 +01:00
parent 71f32f83d3
commit 66ce4ee218
18077 changed files with 2166122 additions and 35184 deletions

View File

@@ -26,11 +26,46 @@ use Thelia\Model\ProductAssociatedContent;
if (php_sapi_name() != 'cli') {
throw new \Exception('this script can only be launched with cli sapi');
}
require __DIR__ . '/../core/bootstrap.php';
$bootstrapToggle = false;
$bootstraped = false;
// Autoload bootstrap
foreach ($argv as $arg) {
if ($arg === '-b') {
$bootstrapToggle = true;
continue;
}
if ($bootstrapToggle) {
require __DIR__ . DIRECTORY_SEPARATOR . $arg;
$bootstraped = true;
}
}
if (!$bootstraped) {
if (isset($bootstrapFile)) {
require $bootstrapFile;
} elseif (is_file($file = __DIR__ . '/../core/vendor/autoload.php')) {
require $file;
} elseif (is_file($file = __DIR__ . '/../../bootstrap.php')) {
// Here we are on a thelia/thelia-project
require $file;
} else {
echo "No autoload file found. Please use the -b argument to include yours";
exit(1);
}
}
$thelia = new Thelia\Core\Thelia("dev", true);
$thelia->boot();
// Load the translator
$thelia->getContainer()->get("thelia.translator");
$faker = Faker\Factory::create();
// Intialize URL management
$url = new Thelia\Tools\URL();
@@ -98,7 +133,7 @@ function createProduct($faker, $categories, $brands, $contents, $template, $attr
{
echo "start creating products\n";
$fileSystem = new \Symfony\Component\Filesystem\Filesystem();
if (($handle = fopen(THELIA_ROOT . '/setup/import/products.csv', "r")) !== FALSE) {
if (($handle = fopen(THELIA_SETUP_DIRECTORY . 'import/products.csv', "r")) !== FALSE) {
$row=0;
while (($data = fgetcsv($handle, 100000, ";")) !== FALSE) {
$row++;
@@ -131,7 +166,7 @@ function createProduct($faker, $categories, $brands, $contents, $template, $attr
->setChapo($data[2])
->setDescription($data[4])
->setPostscriptum($data[6])
->setLocale('fr_Fr')
->setLocale('fr_FR')
->setTitle($data[1])
->setChapo($data[3])
->setDescription($data[5])
@@ -155,7 +190,7 @@ function createProduct($faker, $categories, $brands, $contents, $template, $attr
->setProduct($product)
->setFile($image)
->save($con);
$fileSystem->copy(THELIA_ROOT . 'setup/import/images/'.$image, THELIA_ROOT . 'local/media/images/product/'.$image, true);
$fileSystem->copy(THELIA_SETUP_DIRECTORY . 'import/images/'.$image, THELIA_LOCAL_DIR . 'media/images/product/'.$image, true);
}
$pses = explode(";", $data[12]);
@@ -165,14 +200,14 @@ function createProduct($faker, $categories, $brands, $contents, $template, $attr
$stock = new \Thelia\Model\ProductSaleElements();
$stock->setProduct($product);
$stock->setRef($product->getId() . '_' . uniqid('', true));
$stock->setQuantity($faker->randomNumber(1,50));
$stock->setQuantity($faker->numberBetween(1,50));
if (!empty($data[9])) {
$stock->setPromo(1);
} else {
$stock->setPromo(0);
}
$stock->setNewness($faker->randomNumber(0,1));
$stock->setNewness($faker->numberBetween(0,1));
$stock->setWeight($faker->randomFloat(2, 1,30));
$stock->save($con);
@@ -289,6 +324,8 @@ function createCustomer($faker, $con){
->save($con)
;
}
echo "End creating customer\n";
}
function createMaterials($con)
@@ -298,7 +335,7 @@ function createMaterials($con)
$feature = null;
$features = array();
if (($handle = fopen(THELIA_ROOT . '/setup/import/materials.csv', "r")) !== FALSE) {
if (($handle = fopen(THELIA_SETUP_DIRECTORY . 'import/materials.csv', "r")) !== FALSE) {
$row=0;
$feature = new \Thelia\Model\Feature();
$feature
@@ -339,7 +376,7 @@ function createBrands($faker, $con)
$fileSystem = new \Symfony\Component\Filesystem\Filesystem();
$brands = array();
if (($handle = fopen(THELIA_ROOT . '/setup/import/brand.csv', "r")) !== FALSE) {
if (($handle = fopen(THELIA_SETUP_DIRECTORY . 'import/brand.csv', "r")) !== FALSE) {
$row=0;
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
$row++;
@@ -375,7 +412,7 @@ function createBrands($faker, $con)
if ($logoId === null) {
$logoId = $brandImage->getId();
}
$fileSystem->copy(THELIA_ROOT . 'setup/import/images/'.$image, THELIA_ROOT . 'local/media/images/brand/'.$image, true);
$fileSystem->copy(THELIA_SETUP_DIRECTORY . 'import/images/'.$image, THELIA_LOCAL_DIR . 'media/images/brand/'.$image, true);
}
if ($logoId !== null){
@@ -396,7 +433,7 @@ function createCategories($faker, $con)
{
echo "start creating categories\n";
$categories = array();
if (($handle = fopen(THELIA_ROOT . '/setup/import/categories.csv', "r")) !== FALSE) {
if (($handle = fopen(THELIA_SETUP_DIRECTORY . 'import/categories.csv', "r")) !== FALSE) {
$row=0;
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
$row++;
@@ -431,7 +468,7 @@ function createFolders($faker, $con)
$fileSystem = new \Symfony\Component\Filesystem\Filesystem();
$folders = array();
if (($handle = fopen(THELIA_ROOT . '/setup/import/folders.csv', "r")) !== FALSE) {
if (($handle = fopen(THELIA_SETUP_DIRECTORY . 'import/folders.csv', "r")) !== FALSE) {
$row=0;
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
$row++;
@@ -463,7 +500,7 @@ function createFolders($faker, $con)
->setFolderId($folder->getId())
->setFile($image)
->save($con);
$fileSystem->copy(THELIA_ROOT . 'setup/import/images/'.$image, THELIA_ROOT . 'local/media/images/folder/'.$image, true);
$fileSystem->copy(THELIA_SETUP_DIRECTORY . 'import/images/'.$image, THELIA_LOCAL_DIR . 'media/images/folder/'.$image, true);
}
}
fclose($handle);
@@ -481,7 +518,7 @@ function createContents($faker, $folders, $con)
$fileSystem = new \Symfony\Component\Filesystem\Filesystem();
$contents = array();
if (($handle = fopen(THELIA_ROOT . '/setup/import/contents.csv', "r")) !== FALSE) {
if (($handle = fopen(THELIA_SETUP_DIRECTORY . 'import/contents.csv', "r")) !== FALSE) {
$row=0;
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
$row++;
@@ -532,7 +569,7 @@ function createContents($faker, $folders, $con)
->setContentId($content->getId())
->setFile($image)
->save($con);
$fileSystem->copy(THELIA_ROOT . 'setup/import/images/'.$image, THELIA_ROOT . 'local/media/images/content/'.$image, true);
$fileSystem->copy(THELIA_SETUP_DIRECTORY . 'import/images/'.$image, THELIA_LOCAL_DIR . 'media/images/content/'.$image, true);
}
$contents[trim($data[1])] = $content;
@@ -548,7 +585,7 @@ function createContents($faker, $folders, $con)
function createColors($con)
{
echo "start creating colors attributes\n";
if (($handle = fopen(THELIA_ROOT . '/setup/import/colors.csv', "r")) !== FALSE) {
if (($handle = fopen(THELIA_SETUP_DIRECTORY . 'import/colors.csv', "r")) !== FALSE) {
$row=0;
$attribute = new \Thelia\Model\Attribute();
$attribute
@@ -684,10 +721,16 @@ function clearTables($con)
\Thelia\Model\ProductImageQuery::create()->find($con)->delete($con);
$customer = Thelia\Model\CustomerQuery::create()
$customer = \Thelia\Model\CustomerQuery::create()
->find($con);
$customer->delete($con);
$sale = \Thelia\Model\SaleQuery::create()->find($con);
$sale->delete($con);
$saleProduct = \Thelia\Model\SaleProductQuery::create()->find($con);
$saleProduct->delete($con);
echo "Tables cleared with success\n";
}