<commit_before><?php

namespace App;

use ActiveRecord\RecordNotFound;
use App\Exceptions\JSONParseException;
use App\Models\Appearance;
use App\Models\ColorGroup;
use App\Models\LegacyPostMapping;
use App\Models\Log;
use App\Models\Post;
use App\Models\Show;
use App\Models\DeviantartUser;
use App\Models\ShowVideo;
use cogpowered\FineDiff;
use Exception;
use RuntimeException;
use function count;
use function in_array;

class Logs {
  public const LOG_DESCRIPTION = [
    #--------------------# (max length)
    'rolechange' => 'User group change',
    'userfetch' => 'Fetch user details',
    'req_delete' => 'Request deleted',
    'img_update' => 'Post image updated',
    'res_overtake' => 'Overtook post reservation',
    'appearances' => 'Appearance management',
    'res_transfer' => 'Reservation transferred',
    'cg_modify' => 'Color group modified',
    'cgs' => 'Color group management',
    'cg_order' => 'Color groups re-ordered',
    'appearance_modify' => 'Appearance modified',
    'video_broken' => 'Broken video removed',
    'cm_modify' => 'Appearance CM edited',
    'cm_delete' => 'Appearance CM deleted',
    'post_fix' => 'Broken post restored',
    'staff_limits' => 'Account limitation changed',
    'derpimerge' => 'Derpibooru merge detected',
  ];

  public const FORCE_INITIATOR_WEBSERVER = true;

  /**
   * Logs a specific set of data (action) in the table belonging to the specified type
   *
   * @param string $reftype Log entry type
   * @param array  $data    Data to be inserted
   * @param bool   $forcews Force initiator to be null
   *
   * @return bool
   * @throws RuntimeException
   */
  public static function logAction($reftype, $data = null, $forcews = false) {
    $central = [
      'ip' => $_SERVER['REMOTE_ADDR'],
      'refid' => null,
      'reftype' => $reftype,
      'data' => $data,
    ];

    if (Auth::$signed_in && !$forcews)
      $central['initiator'] = Auth::$user->id;

    return (new Log($central))->save();
  }

  public static $ACTIONS = [
    'add' => '<span class="color-green"><span class="typcn typcn-plus"></span> Create</span>',
    'del' => '<span class="color-red"><span class="typcn typcn-trash"></span> Delete</span>',
  ];

  public const
    KEYCOLOR_INFO = 'blue',
    KEYCOLOR_ERROR = 'red',
    KEYCOLOR_SUCCESS = 'green',
    SKIP_VALUE = [];

  /**
   * Format log entry details
   *
   * @param Log $main_entry Main log entry
   * @param array $data     Data to process (sub-log entry)
   *
   * @return array
   * @throws JSONParseException
   */
  public static function formatEntryDetails(Log $main_entry, array $data) {
    $details = [];<commit_msg>Split log entry data assignment into separate statement<commit_after><?php

namespace App;

use ActiveRecord\RecordNotFound;
use App\Exceptions\JSONParseException;
use App\Models\Appearance;
use App\Models\ColorGroup;
use App\Models\LegacyPostMapping;
use App\Models\Log;
use App\Models\Post;
use App\Models\Show;
use App\Models\DeviantartUser;
use App\Models\ShowVideo;
use cogpowered\FineDiff;
use Exception;
use RuntimeException;
use function count;
use function in_array;

class Logs {
  public const LOG_DESCRIPTION = [
    #--------------------# (max length)
    'rolechange' => 'User group change',
    'userfetch' => 'Fetch user details',
    'req_delete' => 'Request deleted',
    'img_update' => 'Post image updated',
    'res_overtake' => 'Overtook post reservation',
    'appearances' => 'Appearance management',
    'res_transfer' => 'Reservation transferred',
    'cg_modify' => 'Color group modified',
    'cgs' => 'Color group management',
    'cg_order' => 'Color groups re-ordered',
    'appearance_modify' => 'Appearance modified',
    'video_broken' => 'Broken video removed',
    'cm_modify' => 'Appearance CM edited',
    'cm_delete' => 'Appearance CM deleted',
    'post_fix' => 'Broken post restored',
    'staff_limits' => 'Account limitation changed',
    'derpimerge' => 'Derpibooru merge detected',
  ];

  public const FORCE_INITIATOR_WEBSERVER = true;

  /**
   * Logs a specific set of data (action) in the table belonging to the specified type
   *
   * @param string $reftype Log entry type
   * @param array  $data    Data to be inserted
   * @param bool   $forcews Force initiator to be null
   *
   * @return bool
   * @throws RuntimeException
   */
  public static function logAction($reftype, $data = null, $forcews = false) {
    $log = new Log([
      'ip' => $_SERVER['REMOTE_ADDR'],
      'refid' => null,
      'reftype' => $reftype,
    ]);

    if (Auth::$signed_in && !$forcews)
      $log->initiator = Auth::$user->id;

    $log->data = $data;

    return $log->save();
  }

  public static $ACTIONS = [
    'add' => '<span class="color-green"><span class="typcn typcn-plus"></span> Create</span>',
    'del' => '<span class="color-red"><span class="typcn typcn-trash"></span> Delete</span>',
  ];

  public const
    KEYCOLOR_INFO = 'blue',
    KEYCOLOR_ERROR = 'red',
    KEYCOLOR_SUCCESS = 'green',
    SKIP_VALUE = [];

  /**
   * Format log entry details
   *
   * @param Log $main_entry Main log entry
   * @param array $data     Data to process (sub-log entry)
   *
   * @return array
   * @throws JSONParseException
   */
  public static function formatEntryDetails(Log $main_entry, array $data) {
    $details = [];
{'fraction_non_alphanumeric': 0.14678208505833648, 'fraction_numerical': 0.0, 'mean_word_length': 3.4626364399664147, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 70, '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': '6905234', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1681, 'n_words': 466}