Changeset 764


Ignore:
Timestamp:
Mar 12, 2022 11:19:03 PM (2 years ago)
Author:
anonymous
Message:

Add $merge parameter to exclude values from record versioning (e.g., site_add_vars)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Version.inc.php

    r637 r764  
    202202     * @param string $record_val    The value of the key column for the record.
    203203     * @param string $title         The title of this record. Only used for human presentation.
     204     * @param array  $merge         Array of values to merge with the current record values (use this to force 'key' to be an empty string in a saved version, e.g., ['key' => '']).
    204205     *
    205206     * @return int                  The id for the version (mysql last insert id).
    206207     */
    207     public function create($record_table, $record_key, $record_val, $title='', $notes='')
     208    public function create($record_table, $record_key, $record_val, $title='', $notes='', Array $merge=[])
    208209    {
    209210        $app =& App::getInstance();
     
    213214
    214215        // Get current record.
    215         if (!$record = $this->getCurrent($record_table, $record_key, $record_val)) {
     216        if (!$record = $this->getCurrent($record_table, $record_key, $record_val, $merge)) {
    216217            $app->logMsg(sprintf('Could not create %s version, record not found: %s, %s, %s.', $title, $record_table, $record_key, $record_val), LOG_ERR, __FILE__, __LINE__);
    217218            return false;
     
    560561     * Get the current record data from the original table.
    561562     *
    562      * @param string $version_id    The id of the version to restore.
    563      *
    564      * @return mixed                Array of data saved in version, or false if none.
    565      */
    566     public function getCurrent($record_table, $record_key, $record_val)
     563     * @param string $record_table  The table containing the record.
     564     * @param string $record_key    The key column for the record.
     565     * @param string $record_val    The value of the key column for the record.
     566     * @param array  $merge         Array of values to merge with the current record values (use this to redact certain values, e.g., ['key' => '']).
     567     *
     568     * @return mixed                Array of data from the current database record.
     569     */
     570    public function getCurrent($record_table, $record_key, $record_val, Array $merge=[])
    567571    {
    568572        $db =& DB::getInstance();
     
    581585        ");
    582586        if ($record = mysql_fetch_assoc($qid)) {
    583             return $record;
     587            return array_merge($record, $merge);
    584588        } else {
    585589            return false;
Note: See TracChangeset for help on using the changeset viewer.