src/CMDBCategory.php
public function clear($objectID, array $categoryConsts) {
        $batch = $this->batchRead([$objectID], $categoryConsts);

        $requests = [];
        $counter = 0;
        $index = 0;

        foreach ($batch as $entries) {
            $categoryConst = $categoryConsts[$index];

            foreach ($entries as $entry) {
                $requests[] = [
                    'method' => 'cmdb.category.archive',
                    'params' => [
                        'object' => $objectID,
                        'category' => $categoryConst,
                        'entry' => (int) $entry['id']
                    ]
                ];

                $counter++;
            }

            $index++;
        }

        if ($counter === 0) {
            return 0;
        }

        $results = $this->api->batchRequest($requests);

        foreach ($results as $result) {
            if (!array_key_exists('success', $result) ||
                $result['success'] !== true) {
                if (array_key_exists('message', $result)) {
                    throw new RuntimeException(sprintf('Bad result: %s', $result['message']));
                } else {
                    throw new RuntimeException('Bad result');
                }
            }
        }

        return $counter;
    }
public function clear($objectID, array $categoryConsts) {
        $batch = $this->batchRead([$objectID], $categoryConsts);

        $requests = [];
        $counter = 0;
        $index = 0;

        foreach ($batch as $entries) {
            $categoryConst = $categoryConsts[$index];

            foreach ($entries as $entry) {
                $requests[] = [
                    'method' => 'cmdb.category.archive',
                    'params' => [
                        'object' => $objectID,
                        'category' => $categoryConst,
                        'entry' => (int) $entry['id']
                    ]
                ];

                $counter++;
            }

            $index++;
        }

        if ($counter === 0) {
            return 0;
        }

        $results = $this->api->batchRequest($requests);

        foreach ($results as $result) {
            if (!array_key_exists('success', $result) ||
                $result['success'] !== true) {
                if (array_key_exists('message', $result)) {
                    throw new RuntimeException(sprintf('Bad result: %s', $result['message']));
                } else {
                    throw new RuntimeException('Bad result');
                }
            }
        }

        return $counter;
    }
public function clear ( $ objectID , array $ categoryConsts ) { $ batch = $ this -> batchRead ( [ $ objectID ] , $ categoryConsts ) ; $ requests = [ ] ; $ counter = 0 ; $ index = 0 ; foreach ( $ batch as $ entries ) { $ categoryConst = $ categoryConsts [ $ index ] ; foreach ( $ entries as $ entry ) { $ requests [ ] = [ 'method' => 'cmdb.category.archive' , 'params' => [ 'object' => $ objectID , 'category' => $ categoryConst , 'entry' => ( int ) $ entry [ 'id' ] ] ] ; $ counter ++ ; } $ index ++ ; } if ( $ counter === 0 ) { return 0 ; } $ results = $ this -> api -> batchRequest ( $ requests ) ; foreach ( $ results as $ result ) { if ( ! array_key_exists ( 'success' , $ result ) || $ result [ 'success' ] !== true ) { if ( array_key_exists ( 'message' , $ result ) ) { throw new RuntimeException ( sprintf ( 'Bad result: %s' , $ result [ 'message' ] ) ) ; } else { throw new RuntimeException ( 'Bad result' ) ; } } } return $ counter ; }
Archive category entries for a specific object

@param int $objectID Object identifier
@param array $categoryConsts List of category constants as strings

@return int Number of purged category entries

@throws Exception on error
Archive category entries for a specific object