| Server IP : 69.72.244.102 / Your IP : 216.73.216.164 Web Server : LiteSpeed System : Linux s3434.fra1.stableserver.net 4.18.0-513.24.1.lve.2.el8.x86_64 #1 SMP Fri May 24 12:42:50 UTC 2024 x86_64 User : konzalta ( 1271) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/konzalta/public_html/wp-content/plugins/wappointment/app/Models/ |
Upload File : |
<?php
namespace Wappointment\Models;
use Wappointment\Config\Database;
trait CanIgnore
{
/**
* Performs a 'replace' query with the data
* @param array $attributes
* @return bool t/f for success/failure
*/
public static function replace(array $attributes = [])
{
return static::executeQuery('replace', $attributes);
}
/**
* performs an 'insert ignore' query with the data
* @param array $attributes
* @return bool t/f for success/failure
*/
public static function insertIgnore(array $attributes = [])
{
return static::executeQuery('insert ignore', $attributes);
}
public static function upsert(array $attributes = [])
{
return static::executeQuery('insert', $attributes, \true);
}
protected static function executeQuery($command, array $attributes, $upsert = \false)
{
if (!\count($attributes)) {
return \true;
}
$model = new static();
if ($model->fireModelEvent('saving') === \false) {
return \false;
}
$attributes = \WappointmentLv::collect($attributes);
$first = $attributes->first();
if (!\is_array($first)) {
$attributes = \WappointmentLv::collect([$attributes->toArray()]);
}
$keys = \WappointmentLv::collect($attributes->first())->keys()->transform(function ($key) {
return '`' . $key . '`';
});
$bindings = [];
$query = $command . ' into ' . Database::capsule()::getTablePrefix() . $model->getTable() . ' (' . $keys->implode(',') . ') values ';
$inserts = [];
foreach ($attributes as $data) {
$qs = [];
foreach ($data as $attrib => $value) {
$qs[] = '?';
if ($attrib == 'title') {
$bindings[] = \substr($value, 0, 100);
} else {
$bindings[] = $value;
}
}
$inserts[] = '(' . \implode(',', $qs) . ')';
}
$query .= \implode(',', $inserts);
if ($upsert) {
$query .= ' ON DUPLICATE KEY UPDATE ';
foreach ($keys as $i => $key) {
$query .= " {$key} = VALUES({$key}) ";
if ($i < \count($keys) - 1) {
$query .= ',';
}
}
$query .= ';';
}
$connec = Database::capsule()::connection($model->getConnectionName());
$rowsInserted = $connec->affectingStatement($query, $bindings);
$model->fireModelEvent('saved', \false);
return $rowsInserted;
}
}