<?php

$contentData = false;
if($section){
    $contentData = json_decode($section->content_data, true);
}
if(!$contentData || !isset($contentData['value'])) {
    $contentData = [
        'value'=>0,
        'actionLog'=>[]
    ];
}

$action = $request->get('action');
$actionLog = [];
if($action == 'INC'){
    $actionLog = ['action'=>$action, 'oldValue'=>$contentData['value']];
    $contentData['value'] = $contentData['value']+1;
    $actionLog['newValue'] = $contentData['value'];
}

if($action == 'DEC'){
    $actionLog = ['action'=>$action, 'oldValue'=>$contentData['value']];
    $contentData['value'] = $contentData['value']-1;
    $actionLog['newValue'] = $contentData['value'];
}

$contentData['actionLog'][] = $actionLog;

$newContentData = $contentData;