Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/bolt/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ accept_media_types: [ gif, jpg, jpeg, png, svg, pdf, mp3, tiff ]
#`post_max_size` and `upload_max_filesize` in `php.ini`.
accept_upload_size: 8M

# Default location for uploading files.
upload_location: "{year}/{month}/{contenttype}/"

# Options to use with curl requests.
Expand Down
20 changes: 20 additions & 0 deletions src/DataFixtures/ContentFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,26 @@ private function getPresetRecords(): array
'title' => 'Search',
'slug' => 'search',
];
$records['blocks'][] = [
'title' => 'Our People',
'slug' => 'people',
];
$records['blocks'][] = [
'title' => 'Call to Action',
'slug' => 'call-to-action',
];
$records['blocks'][] = [
'title' => 'Hero Section',
'slug' => 'hero-section',
];
$records['blocks'][] = [
'title' => 'Introduction',
'slug' => 'introduction',
];
$records['blocks'][] = [
'title' => 'Newsletter',
'slug' => 'newsletter',
];
$records['blocks'][] = [
'title' => '404 Page not found',
'slug' => '404-not-found',
Expand Down
34 changes: 21 additions & 13 deletions src/DataFixtures/ImageFetchFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ImageFetchFixtures extends BaseFixture implements FixtureGroupInterface
/** @var FileLocations */
private $fileLocations;

private const AMOUNT = 10;
private const AMOUNT = 20;
private const MAX_AMOUNT = 50;

/** @var array */
Expand All @@ -30,10 +30,12 @@ class ImageFetchFixtures extends BaseFixture implements FixtureGroupInterface
public function __construct(FileLocations $fileLocations, Config $config)
{
$this->urls = new Collection([
'https://source.unsplash.com/1280x1024/?business,workspace,interior/',
'https://source.unsplash.com/1280x1024/?cityscape,landscape,nature/',
'https://source.unsplash.com/1280x1024/?animal,kitten,puppy,cute/',
'https://source.unsplash.com/1280x1024/?technology/',
['stock', 'https://source.unsplash.com/1280x1024/?business,workspace,interior/'],
['stock', 'https://source.unsplash.com/1280x1024/?cityscape,landscape,nature/'],
['stock', 'https://source.unsplash.com/1280x1024/?technology,product/'],
['animal', 'https://source.unsplash.com/1280x1024/?animal,kitten,puppy,cute/'],
['people', 'https://source.unsplash.com/1280x1024/?portrait,face,headshot/'],
['people', 'https://source.unsplash.com/1280x1024/?portrait,face,headshot/'],
]);

$this->curlOptions = $config->get('general/curl_options')->all();
Expand All @@ -58,23 +60,18 @@ public function load(ObjectManager $manager): void

private function fetchImages(): void
{
$outputPath = $this->fileLocations->get('files')->getBasepath() . '/stock/';

if (! is_dir($outputPath)) {
mkdir($outputPath);
}

$output = new ConsoleOutput();
$progressBar = new ProgressBar($output, self::AMOUNT);

$progressBar->start();

for ($i = 1; $i <= self::AMOUNT; $i++) {
$url = $this->urls->random() . random_int(10000, 99999);
$random = $this->urls->random();
$url = $random[1] . random_int(10000, 99999);
$filename = 'image_' . random_int(10000, 99999) . '.jpg';

$client = HttpClient::create();
$resource = fopen($outputPath . $filename, 'w');
$resource = fopen($this->getOutputPath($random[0]) . $filename, 'w');

$image = $client->request('GET', $url, $this->curlOptions)->getContent();

Expand All @@ -87,4 +84,15 @@ private function fetchImages(): void
$progressBar->finish();
$output->writeln('');
}

private function getOutputPath(string $sub): string
{
$outputPath = $this->fileLocations->get('files')->getBasepath() . '/' . $sub . '/';

if (! is_dir($outputPath)) {
mkdir($outputPath);
}

return $outputPath;
}
}