Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4100041
UndoLog.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
UndoLog.php
View Options
<?php
namespace
MediaWiki\Maintenance
;
use
Wikimedia\Rdbms\IDatabase
;
/**
* Update a database while optionally writing SQL that reverses the update to
* a file.
*/
class
UndoLog
{
/** @var resource */
private
$file
;
/** @var IDatabase */
private
$dbw
;
/**
* @param string|null $fileName
* @param IDatabase $dbw
*/
public
function
__construct
(
$fileName
,
IDatabase
$dbw
)
{
if
(
$fileName
!==
null
)
{
$this
->
file
=
fopen
(
$fileName
,
'a'
);
if
(
!
$this
->
file
)
{
throw
new
\RuntimeException
(
'Unable to open undo log'
);
}
}
$this
->
dbw
=
$dbw
;
}
/**
* @param string $table
* @param array $newValues
* @param array $oldValues
* @param string $fname
* @return bool
*/
public
function
update
(
$table
,
array
$newValues
,
array
$oldValues
,
$fname
)
{
$this
->
dbw
->
newUpdateQueryBuilder
()
->
update
(
$table
)
->
set
(
$newValues
)
->
where
(
$oldValues
)
->
caller
(
$fname
)->
execute
();
$updated
=
(
bool
)
$this
->
dbw
->
affectedRows
();
if
(
$this
->
file
&&
$updated
)
{
$table
=
$this
->
dbw
->
tableName
(
$table
);
fwrite
(
$this
->
file
,
"UPDATE $table"
.
' SET '
.
$this
->
dbw
->
makeList
(
$oldValues
,
IDatabase
::
LIST_SET
)
.
' WHERE '
.
$this
->
dbw
->
makeList
(
$newValues
,
IDatabase
::
LIST_AND
)
.
";
\n
"
);
}
return
$updated
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 16:11 (3 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
94/57/6e7df7eb95bac28e29bddb12c5cd
Default Alt Text
UndoLog.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment