Finalized images action and loop
This commit is contained in:
@@ -20,4 +20,7 @@ Variables Config à initialiser:
|
||||
- form.secret : token csrf
|
||||
- verifyStock : vérification du stock lors du paiement/ajout au panier. Defaut 1
|
||||
- default_images_quality_percent : qualité par défaut des images générées (0 à 100, défaut: 75).
|
||||
- original_image_delivery_mode : mode de mise à disposition des images originales (full resolution) dans le cache. 'symlink' pour un lien symbolique, 'copy' pour une copie
|
||||
- original_image_delivery_mode : mode de mise à disposition des images originales (full resolution) dans le cache. 'symlink' pour un lien symbolique, 'copy' pour une copie
|
||||
- images_library_path : chemin vers le répertoire où sont stockés les images source (defaut: local/media/images)
|
||||
- image_cache_dir_from_web_root : le repértoire de base où sont cachées les images, relatif à /web (cache/images)
|
||||
- imagine_graphic_driver : le drivers utilisé par Imagine (gd, imagik, gmagick), defaut: 'gd'
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
<?php
|
||||
use Thelia\Model\ProductImage;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Thelia\Model\CategoryImage;
|
||||
use Thelia\Model\FolderImage;
|
||||
use Thelia\Model\ContentImage;
|
||||
require __DIR__ . '/../core/bootstrap.php';
|
||||
|
||||
$thelia = new Thelia\Core\Thelia("dev", true);
|
||||
@@ -10,8 +15,37 @@ $con->beginTransaction();
|
||||
|
||||
$currency = \Thelia\Model\CurrencyQuery::create()->filterByCode('EUR')->findOne();
|
||||
|
||||
function generate_image($image, $position, $typeobj, $id) {
|
||||
|
||||
global $faker;
|
||||
|
||||
$image
|
||||
->setTitle($faker->text(20))
|
||||
->setDescription($faker->text(250))
|
||||
->setChapo($faker->text(40))
|
||||
->setPostscriptum($faker->text(40))
|
||||
->setPosition($position)
|
||||
->setFile(sprintf("sample-image-%s.png", $id))
|
||||
->save()
|
||||
;
|
||||
|
||||
// Generate images
|
||||
$image_data = file_get_contents("http://placehold.it/320x200&text=Image+for+$typeobj+ID+".$id);
|
||||
$image_file = sprintf("%s/../local/media/images/%s/sample-image-%s.png", __DIR__, $typeobj, $id);
|
||||
|
||||
if (! is_dir(dirname($image_file))) mkdir(dirname($image_file), 0777, true);
|
||||
|
||||
if ($fh = fopen($image_file, "w")) {
|
||||
fwrite($fh, $image_data);
|
||||
fclose($fh);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$stmt = $con->prepare("SET foreign_key_checks = 0");
|
||||
$stmt->execute();
|
||||
|
||||
$category = Thelia\Model\CategoryQuery::create()
|
||||
->find();
|
||||
$category->delete();
|
||||
@@ -50,6 +84,9 @@ try {
|
||||
->find();
|
||||
$content->delete();
|
||||
|
||||
$stmt = $con->prepare("SET foreign_key_checks = 1");
|
||||
$stmt->execute();
|
||||
|
||||
//first category
|
||||
$sweet = new Thelia\Model\Category();
|
||||
$sweet->setParent(0);
|
||||
@@ -60,6 +97,10 @@ try {
|
||||
|
||||
$sweet->save();
|
||||
|
||||
$image = new CategoryImage();
|
||||
$image->setCategoryId($sweet->getId());
|
||||
generate_image($image, 1, 'category', $sweet->getId());
|
||||
|
||||
//second category
|
||||
$jeans = new Thelia\Model\Category();
|
||||
$jeans->setParent(0);
|
||||
@@ -70,6 +111,10 @@ try {
|
||||
|
||||
$jeans->save();
|
||||
|
||||
$image = new CategoryImage();
|
||||
$image->setCategoryId($jeans->getId());
|
||||
generate_image($image, 2, 'category', $jeans->getId());
|
||||
|
||||
//third category
|
||||
$other = new Thelia\Model\Category();
|
||||
$other->setParent($jeans->getId());
|
||||
@@ -80,6 +125,10 @@ try {
|
||||
|
||||
$other->save();
|
||||
|
||||
$image = new CategoryImage();
|
||||
$image->setCategoryId($other->getId());
|
||||
generate_image($image, 3, 'category', $other->getId());
|
||||
|
||||
for ($i=1; $i <= 5; $i++) {
|
||||
$product = new \Thelia\Model\Product();
|
||||
$product->addCategory($sweet);
|
||||
@@ -102,8 +151,12 @@ try {
|
||||
$productPrice->setProductSaleElements($stock);
|
||||
$productPrice->setCurrency($currency);
|
||||
$productPrice->setPrice($faker->randomFloat(2, 20, 2500));
|
||||
|
||||
$productPrice->save();
|
||||
|
||||
$image = new ProductImage();
|
||||
$image->setProductId($product->getId());
|
||||
generate_image($image, $i, 'product', $product->getId());
|
||||
}
|
||||
|
||||
for ($i=1; $i <= 5; $i++) {
|
||||
@@ -130,6 +183,10 @@ try {
|
||||
$productPrice->setPrice($faker->randomFloat(2, 20, 2500));
|
||||
$productPrice->save();
|
||||
|
||||
$image = new ProductImage();
|
||||
$image->setProductId($product->getId());
|
||||
generate_image($image, $i, 'product', $product->getId());
|
||||
|
||||
}
|
||||
|
||||
//folders and contents
|
||||
@@ -143,6 +200,10 @@ try {
|
||||
|
||||
$folder->save();
|
||||
|
||||
$image = new FolderImage();
|
||||
$image->setFolderId($folder->getId());
|
||||
generate_image($image, $i, 'folder', $folder->getId());
|
||||
|
||||
for($j=0; $j<rand(0, 4); $j++) {
|
||||
$subfolder = new Thelia\Model\Folder();
|
||||
$subfolder->setParent($folder->getId());
|
||||
@@ -153,6 +214,10 @@ try {
|
||||
|
||||
$subfolder->save();
|
||||
|
||||
$image = new FolderImage();
|
||||
$image->setFolderId($subfolder->getId());
|
||||
generate_image($image, $j, 'folder', $subfolder->getId());
|
||||
|
||||
for($k=0; $k<rand(1, 5); $k++) {
|
||||
$content = new Thelia\Model\Content();
|
||||
$content->addFolder($subfolder);
|
||||
@@ -162,6 +227,11 @@ try {
|
||||
$content->setDescription($faker->text(255));
|
||||
|
||||
$content->save();
|
||||
|
||||
$image = new ContentImage();
|
||||
$image->setContentId($content->getId());
|
||||
generate_image($image, $k, 'content', $content->getId());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,8 +258,13 @@ try {
|
||||
}
|
||||
|
||||
$con->commit();
|
||||
} catch (Exception $e) {
|
||||
echo "error : ".$e->getMessage()."\n";
|
||||
}
|
||||
catch (PropelException $pe) {
|
||||
echo "Propel error: ".$pe->getMessage()."\n".$pe->getTraceAsString();
|
||||
$con->rollBack();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
echo "error occured : ".$e->getMessage()."\n".$e->getTraceAsString();
|
||||
$con->rollBack();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ INSERT INTO `lang`(`id`,`title`,`code`,`locale`,`url`,`by_default`,`position`,`c
|
||||
INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updated_at`) VALUES
|
||||
('session_config.default', '1', 1, 1, NOW(), NOW()),
|
||||
('verifyStock', '1', 1, 0, NOW(), NOW());
|
||||
('imagine_driver', 'gd', 1, 0, NOW(), NOW());
|
||||
('imagine_graphic_driver', 'gd', 1, 0, NOW(), NOW());
|
||||
('default_images_quality_percent', '75', 1, 0, NOW(), NOW());
|
||||
('original_image_delivery_mode', 'symlink', 1, 0, NOW(), NOW());
|
||||
|
||||
|
||||
@@ -521,6 +521,7 @@ CREATE TABLE `lang`
|
||||
`code` VARCHAR(10),
|
||||
`locale` VARCHAR(45),
|
||||
`url` VARCHAR(255),
|
||||
`position` INTEGER NOT NULL,
|
||||
`by_default` TINYINT,
|
||||
`created_at` DATETIME,
|
||||
`updated_at` DATETIME,
|
||||
@@ -719,6 +720,7 @@ CREATE TABLE `currency`
|
||||
`code` VARCHAR(45),
|
||||
`symbol` VARCHAR(45),
|
||||
`rate` FLOAT,
|
||||
`position` INTEGER NOT NULL,
|
||||
`by_default` TINYINT,
|
||||
`created_at` DATETIME,
|
||||
`updated_at` DATETIME,
|
||||
|
||||
Reference in New Issue
Block a user