<commit_before><?php

use Ulrichsg\Getopt\Getopt;
use Ulrichsg\Getopt\Option;

require_once dirname(__DIR__) . '/include/init.php';


function deleteObject($id)
{
    global $getopt;
    
    if ($getopt[ 'topics' ])
    {
        deleteTopic($id);
    }
    elseif ($getopt[ 'associations' ])
    {
        deleteAssociation($id);
    }
}


function deleteTopic($topic_id)
{
    global $topicmap;
    global $getopt;
    
    $topic = $topicmap->newTopic();
    $topic->load($topic_id);
    
    if ($getopt[ 'with_associations' ])
    {
        foreach ($topicmap->getAssociations([ 'role_player_id' => $topic_id ]) as $association_id)
            deleteAssociation($association_id);
    }
    
    $ok = $topic->delete();<commit_msg>bin/delete.php: Fixed fatal error when using --with-associations.<commit_after><?php

use Ulrichsg\Getopt\Getopt;
use Ulrichsg\Getopt\Option;

require_once dirname(__DIR__) . '/include/init.php';


function deleteObject($id)
{
    global $getopt;
    
    if ($getopt[ 'topics' ])
    {
        deleteTopic($id);
    }
    elseif ($getopt[ 'associations' ])
    {
        deleteAssociation($id);
    }
}


function deleteTopic($topic_id)
{
    global $topicmap;
    global $getopt;
    
    $topic = $topicmap->newTopic();
    $topic->load($topic_id);
    
    if ($getopt[ 'with_associations' ])
    {
        foreach ($topicmap->getAssociationIds([ 'role_player_id' => $topic_id ]) as $association_id)
            deleteAssociation($association_id);
    }
    
    $ok = $topic->delete();
{'fraction_non_alphanumeric': 0.15137614678899083, 'fraction_numerical': 0.0, 'mean_word_length': 2.8658227848101268, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4066877', 'n_tokens_mistral': 530, 'n_tokens_neox': 523, 'n_words': 87}