Удаление всех изображений у товара (msGallery)

Пробую в цикле удалить и добавить фото к товару. С «добавить» нет проблем, вроде разобрался.

$data = [
    'id' => '761',
    'file' => 'assets/images/img.jpg',
];

$response = $modx->runProcessor('gallery/upload', $data, [
    'processors_path' => MODX_CORE_PATH . 'components/minishop2/processors/mgr/',
]);
Как удалить у товара с id=761 все изображения из галереи?
Процессор gallery/remove вроде не для этого…
Сергей
01 апреля 2022, 20:26
modx.pro
203
0

Комментарии: 4

Артур
01 апреля 2022, 23:54
+1
<?php
$resource = $modx->getObject('msProduct', 761);
if($files = $resource->getMany('Files')){
    foreach($files as $f){
        $f->remove();
    }
}
Файлы удалятся, записи в БД удалятся, папка с assets/images/761/small останется. Соответственно, превью остается, потому что она в другой таблице лежит. Можно сделать дополнительно так
<?php
$resource->set('thumb', '');
$resource->save();
    Сергей
    02 апреля 2022, 18:17
    0
    Большое спасибо! Фото товара удаляется и создается.

    Но в логах появилась ошибка:

    [2022-04-02 18:12:05] (ERROR @ /home/users/j/*************/domains/*************.ru/core/components/minishop2/model/minishop2/msproductfile.class.php : 190) [miniShop2] Could not generate thumbnail for "/assets/images/products/127/sp01rm.jpg". Array
    (
        [0] => phpThumb() v1.7.16-202012161640 in file "phpthumb.class.php" on line 234
        [1] => setCacheDirectory() starting with config_cache_directory = "/home/users/j/*************/domains/*************.ru/core/cache/phpthumb/" in file "phpthumb.class.php" on line 1048
        [2] => setting config_cache_directory to $this->realPathSafe(/home/users/j/*************/domains/*************.ru/core/cache/phpthumb) = "/home/users/j/*************/domains/*************.ru/core/cache/phpthumb" in file "phpthumb.class.php" on line 1076
        [3] => setSourceFilename(/home/users/j/*************/domains/*************.ru/ms_jmsg0U) set $this->sourceFilename to "/home/users/j/*************/domains/*************.ru/ms_jmsg0U" in file "phpthumb.class.php" on line 299
        [4] => Addding ImageMagick formats to $AvailableImageOutputFormats (text;ico;bmp;wbmp;gif;png;jpeg) in file "phpthumb.class.php" on line 1006
        [5] => $AvailableImageOutputFormats = array(text;ico;bmp;wbmp;gif;png;jpeg;webp) in file "phpthumb.class.php" on line 1012
        [6] => $this->thumbnailFormat set to $this->config_output_format "jpeg" in file "phpthumb.class.php" on line 1023
        [7] => $this->thumbnailFormat set to $this->f "webp" in file "phpthumb.class.php" on line 1030
        [8] => $this->thumbnailQuality set to "90" in file "phpthumb.class.php" on line 1040
        [9] => $this->sourceFilename set to "/home/users/j/*************/domains/*************.ru/ms_jmsg0U" in file "phpthumb.class.php" on line 933
        [10] => SetCacheFilename() _src set from md5($this->sourceFilename) "/home/users/j/*************/domains/*************.ru/ms_jmsg0U" = "5ec982fbf998889e03e617f327ec8b8d" in file "phpthumb.class.php" on line 3616
        [11] => SetCacheFilename() _par set from md5(_bgffffff_farC_zc1_h400_w400_dpi150) in file "phpthumb.class.php" on line 3655
        [12] => starting ExtractEXIFgetImageSize() in file "phpthumb.class.php" on line 3409
        [13] => getimagesize(/home/users/j/*************/domains/*************.ru/ms_jmsg0U) says image is 800x800 in file "phpthumb.class.php" on line 3419
        [14] => $this->useRawIMoutput=false because "bg" is set in file "phpthumb.class.php" on line 1649
        [15] => $this->useRawIMoutput=false after checking $UnAllowedParameters in file "phpthumb.class.php" on line 1655
        [16] => phpThumb_tempnam() returning "/home/users/j/*************/domains/*************.ru/core/cache/phpthumb/pThumbzm75H2" in file "phpthumb.class.php" on line 4498
        [17] => ImageMagickSwitchAvailable(thumbnail) = 1 in file "phpthumb.class.php" on line 1581
        [18] => getimagesize(/home/users/j/*************/domains/*************.ru/ms_jmsg0U) SUCCEEDED: Array
    (
        [0] => 800
        [1] => 800
        [2] => 2
        [3] => width="800" height="800"
        [bits] => 8
        [channels] => 3
        [mime] => image/jpeg
    )
     in file "phpthumb.class.php" on line 1750
        [19] => ImageMagickSwitchAvailable(density) = 1 in file "phpthumb.class.php" on line 1581
        [20] => getimagesize(/home/users/j/*************/domains/*************.ru/ms_jmsg0U) returned [w=800;h=800;f=2] in file "phpthumb.class.php" on line 1765
        [21] => source dimensions set to 800x800 in file "phpthumb.class.php" on line 1768
        [22] => SetOrientationDependantWidthHeight() starting with "800"x"800" in file "phpthumb.class.php" on line 3388
        [23] => SetOrientationDependantWidthHeight() setting w="400", h="400" in file "phpthumb.class.php" on line 3404
        [24] => ImageMagickSwitchAvailable(repage) = 1 in file "phpthumb.class.php" on line 1581
        [25] => Remaining $this->fltr after ImageMagick: (array(0) { } ) in file "phpthumb.class.php" on line 2316
        [26] => ImageMagick called as (convert '/home/users/j/*************/domains/*************.ru/ms_jmsg0U[0]' -flatten -density '150' -thumbnail 'x400' -gravity center -crop '400x400+0+0' +repage png:'/home/users/j/*************/domains/*************.ru/core/cache/phpthumb/pThumbzm75H2' 2>&1) in file "phpthumb.class.php" on line 2334
        [27] => getimagesize(/home/users/j/*************/domains/*************.ru/core/cache/phpthumb/pThumbzm75H2) returned [w=400;h=400;f=3] in file "phpthumb.class.php" on line 2351
        [28] => ImageMagickThumbnailToGD::imagecreatefrompng() succeeded, $this->gdimg_source is now (400x400) in file "phpthumb.class.php" on line 2357
        [29] => ImageMagickThumbnailToGD() returning $this->IMresizedData (102449 bytes) in file "phpthumb.class.php" on line 2358
        [30] => deleting "/home/users/j/*************/domains/*************.ru/core/cache/phpthumb/pThumbzm75H2" in file "phpthumb.class.php" on line 2364
        [31] => skipping SourceImageToGD() because $this->gdimg_source is already a resource (400x400) in file "phpthumb.class.php" on line 3778
        [32] => CalculateThumbnailDimensions() starting with [W,H,sx,sy,sw,sh] initially set to [400,400,,,,] in file "phpthumb.class.php" on line 3260
        [33] => CalculateThumbnailDimensions() starting with [x,y,w,h] initially set to [0,0,400,400] in file "phpthumb.class.php" on line 3275
        [34] => CreateGDoutput() returning canvas "400x400" in file "phpthumb.class.php" on line 3383
        [35] => ImageResizeFunction($o, $s, 0, 0, 0, 0, 400, 400, 400, 400) in file "phpthumb.class.php" on line 4473
        [36] => memory_get_usage() after copy-resize = 27499336 in file "phpthumb.class.php" on line 433
        [37] => memory_get_usage() after imagedestroy = 26672832 in file "phpthumb.class.php" on line 435
        [38] => AntiOffsiteLinking() says this is allowed in file "phpthumb.class.php" on line 2578
        [39] => skipping AlphaChannelFlatten() because ($this->thumbnailFormat == "webp") in file "phpthumb.class.php" on line 2642
        [40] => GenerateThumbnail() completed successfully in file "phpthumb.class.php" on line 447
        [41] => imageinterlace($this->gdimg_output, 1) in file "phpthumb.class.php" on line 483
        [42] => RenderOutput() attempting imagewebp($this->gdimg_output) in file "phpthumb.class.php" on line 486
        [43] => GD does not have required built-in support for WebP output in file "phpthumb.class.php" on line 552
    )
    С чем она может быть связана?
    Проверил все права на папки все в норме.
    Так же выставил «phpthumb_allow_src_above_docroot» = «Да»
      Артур
      02 апреля 2022, 23:28
      +1
      Очевидно что проблема с формированием превью через phpthumb кажется не может переформатировать в webp, не знаю с чем это связано, вряд ли с удалением фотографий.
        Сергей
        04 апреля 2022, 10:41
        0
        Оказалось что на хосте версия php 5.6.
        Обновление до 7.4. помогло устранить ошибку.
    Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
    4