2015-09-23 13:51:41 +00:00
|
|
|
<?php
|
|
|
|
|
2018-08-09 09:49:10 +00:00
|
|
|
namespace PortableInfobox\Helpers;
|
2015-09-23 13:51:41 +00:00
|
|
|
|
|
|
|
class PagePropsProxy {
|
|
|
|
|
2018-10-11 18:26:59 +00:00
|
|
|
protected $atomicStarted;
|
|
|
|
protected $manualWrite;
|
|
|
|
|
|
|
|
public function __construct( $manualWrite = false ) {
|
|
|
|
$this->manualWrite = $manualWrite;
|
|
|
|
}
|
|
|
|
|
2015-09-23 13:51:41 +00:00
|
|
|
public function get( $id, $property ) {
|
2018-08-02 16:03:45 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
|
|
|
$propValue = $dbr->selectField(
|
|
|
|
'page_props',
|
2018-08-16 09:25:53 +00:00
|
|
|
'pp_value',
|
|
|
|
[
|
2018-08-02 16:03:45 +00:00
|
|
|
'pp_page' => $id,
|
|
|
|
'pp_propname' => $property
|
2018-08-16 09:25:53 +00:00
|
|
|
],
|
2018-08-02 16:03:45 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
return $propValue;
|
2015-09-23 13:51:41 +00:00
|
|
|
}
|
|
|
|
|
2018-08-16 09:25:53 +00:00
|
|
|
public function set( $id, array $props ) {
|
2021-09-10 02:52:19 +00:00
|
|
|
$dbw = wfGetDB( DB_PRIMARY );
|
2018-10-11 18:26:59 +00:00
|
|
|
|
|
|
|
if ( !$this->atomicStarted ) {
|
|
|
|
$dbw->startAtomic( __METHOD__ );
|
|
|
|
$this->atomicStarted = true;
|
|
|
|
}
|
|
|
|
|
2018-08-16 09:25:53 +00:00
|
|
|
foreach ( $props as $sPropName => $sPropValue ) {
|
2018-08-02 16:03:45 +00:00
|
|
|
$dbw->replace(
|
2018-10-11 18:26:59 +00:00
|
|
|
'page_props',
|
2018-08-16 09:25:53 +00:00
|
|
|
[
|
2021-10-13 19:58:43 +00:00
|
|
|
[
|
|
|
|
'pp_page',
|
|
|
|
'pp_propname'
|
|
|
|
]
|
2018-08-16 09:25:53 +00:00
|
|
|
],
|
|
|
|
[
|
2018-10-11 18:26:59 +00:00
|
|
|
'pp_page' => $id,
|
|
|
|
'pp_propname' => $sPropName,
|
|
|
|
'pp_value' => $sPropValue
|
2018-08-16 09:25:53 +00:00
|
|
|
],
|
2018-08-02 16:03:45 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
|
|
|
}
|
2018-10-11 18:26:59 +00:00
|
|
|
|
|
|
|
if ( !$this->manualWrite ) {
|
|
|
|
$dbw->endAtomic( __METHOD__ );
|
|
|
|
$this->atomicStarted = false;
|
|
|
|
}
|
2015-09-23 13:51:41 +00:00
|
|
|
}
|
|
|
|
|
2018-10-11 18:26:59 +00:00
|
|
|
public function write() {
|
|
|
|
if ( $this->atomicStarted && $this->manualWrite ) {
|
2021-09-10 02:52:19 +00:00
|
|
|
wfGetDB( DB_PRIMARY )->endAtomic( __CLASS__ . '::set' );
|
2018-10-11 18:26:59 +00:00
|
|
|
$this->atomicStarted = false;
|
|
|
|
}
|
|
|
|
}
|
2015-09-23 13:51:41 +00:00
|
|
|
}
|