PortableInfobox/includes/services/Helpers/PagePropsProxy.php
Universal Omega 79046437fd
Add CI (#3)
2021-09-09 20:52:19 -06:00

65 lines
1.2 KiB
PHP

<?php
namespace PortableInfobox\Helpers;
class PagePropsProxy {
protected $atomicStarted;
protected $manualWrite;
public function __construct( $manualWrite = false ) {
$this->manualWrite = $manualWrite;
}
public function get( $id, $property ) {
$dbr = wfGetDB( DB_REPLICA );
$propValue = $dbr->selectField(
'page_props',
'pp_value',
[
'pp_page' => $id,
'pp_propname' => $property
],
__METHOD__
);
return $propValue;
}
public function set( $id, array $props ) {
$dbw = wfGetDB( DB_PRIMARY );
if ( !$this->atomicStarted ) {
$dbw->startAtomic( __METHOD__ );
$this->atomicStarted = true;
}
foreach ( $props as $sPropName => $sPropValue ) {
$dbw->replace(
'page_props',
[
'pp_page',
'pp_propname'
],
[
'pp_page' => $id,
'pp_propname' => $sPropName,
'pp_value' => $sPropValue
],
__METHOD__
);
}
if ( !$this->manualWrite ) {
$dbw->endAtomic( __METHOD__ );
$this->atomicStarted = false;
}
}
public function write() {
if ( $this->atomicStarted && $this->manualWrite ) {
wfGetDB( DB_PRIMARY )->endAtomic( __CLASS__ . '::set' );
$this->atomicStarted = false;
}
}
}