if($market_item) $is_ready_to_update = floor((time() - strtotime($market_item->updated_at->format('Y-m-d'))) / 86400) >= 1;
if (!$market_item or $is_ready_to_update) {
file_put_contents('tmp.png', file_get_contents(array_shift($valid_photos)));
$main_photo = upload_photo('tmp.png', 1, $group_id_positive);
$uploaded_photos_id = array_map(function ($valid_photo) use ($group_id_positive) {
file_put_contents('tmp.png', file_get_contents($valid_photo));
return upload_photo('tmp.png', 0, $group_id_positive);
}, $valid_photos);
}
if ($uploaded_photos_id) {
$params = [
'owner_id' => $group_id_negative,
'name' => $offer->type . ', ' . $offer->property_type . ' ' . $offer->category,
'description' => $offer->description,
'category_id' => CATEGORIES[intval($offer->{'category-id'})],
'price' => intval($offer->price->value),
'main_photo_id' => $main_photo,
'photo_ids' => $uploaded_photos_id
];
if (!$market_item) {
$response = $vk->market()->add(ACCESS_TOKEN, $params);
MarketItem::create([
'internal_id' => $offer['internal-id'],
'market_item_id' => $response['market_item_id'],
'vk_group_id' => $group_id_negative]);
echo $offer['internal-id'] . ' created';
echo PHP_EOL;
} else {
if ($is_ready_to_update) {
$params['item_id'] = $market_item->market_item_id;
$response = $vk->market()->edit(ACCESS_TOKEN, $params);
$market_item->touch();
echo $offer['internal-id'] . ' updated';
echo PHP_EOL;
}
}
}
file_put_contents('tmp.png', file_get_contents(array_shift($valid_photos)));
echo $offer['internal-id'] . ' updated';
echo PHP_EOL;
CATEGORIES[intval($offer->{'category-id'})]
вот это однозначно выносить в отдельную функцию, что то вида findCategoryByOffer().if ($uploaded_photos_id) {
Notice: undefined variable вам здесь может быть обеспечена.