HEX
Server: LiteSpeed
System: Linux server315.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: globfdxw (6114)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/globfdxw/www/wp-content/plugins/give/src/TestData/Framework/MetaRepository.php
<?php

namespace Give\TestData\Framework;

class MetaRepository
{

    /** @var string */
    protected $tableName;

    /** @var string */
    protected $relationshipColumnName;

    /**
     * @param string $relationshipColumnName
     */
    public function __construct($tableName, $relationshipColumnName)
    {
        global $wpdb;
        $this->wpdb = $wpdb;
        $this->tableName = $wpdb->prefix . $tableName;
        $this->relationshipColumnName = $relationshipColumnName;
    }

    public function persist($relationshipID, $metaData)
    {
        $values = array_map(
            function ($metaKey, $metaValue) use ($relationshipID) {
                return sprintf("( %s, '%s', '%s' )", $relationshipID, esc_sql($metaKey), esc_sql($metaValue));
            },
            array_keys($metaData),
            $metaData
        );

        $this->wpdb->query(
            $this->getSql($values)
        );
    }

    protected function getSql($values)
    {
        $format = "INSERT INTO $this->tableName {$this->getColumns()} VALUES %s";

        return sprintf($format, implode(',', $values));
    }

    protected function getColumns()
    {
        return sprintf('( %s, meta_key, meta_value )', $this->relationshipColumnName);
    }
}