Update the original name of a record

@staticvar \PDO_statement $stmt
@param \databox $databox
@param array    $record
432097
protected function setOriginalName(\databox $databox, array $record)
    {
        static $stmt;

        if (!isset($stmt[$databox->get_sbas_id()])) {
            $sql = 'UPDATE record SET originalname = :originalname WHERE record_id = :record_id';
            $stmt[$databox->get_sbas_id()] = $databox->get_connection()->prepare($sql);
        }

        $original = '';

        if (false !== $sxe = simplexml_load_string($record['xml'])) {
            foreach ($sxe->doc->attributes() as $key => $value) {
                if (trim($key) != 'originalname') {
                    continue;
                }
                $original = basename(trim($value));
                break;
            }
        }

        $stmt[$databox->get_sbas_id()]->execute([':originalname' => $original, ':record_id'    => $record['record_id']]);
    }
57320
public function bind(PDOStatement $pdo_statement, array $data = [])
    {
        foreach ($data as $key => $value) {
            if (is_null($value) || strtolower($value) === 'null') {
                $pdo_statement->bindValue(
                    ':' . $key,
                    $value,
                    PDO::PARAM_NULL
                );
                
                unset($data[$key]);
            }
        }

        foreach ($data as $key => $value) {
            $param = PDO::PARAM_INT;

            if (preg_match('/[a-z0-9A-Z_-]+|éàèëïùöôîüµ$£!?\.\+,;:/', $value) && !is_numeric($value)) {
                /**
                 * SECURITY OF DATA
                 * - Injection SQL
                 * - XSS
                 */
                $param = PDO::PARAM_STR;
            } else {
                /**
                 * We force the value in whole or in reel.
                 */
                if (is_int($value)) {
                    $value = (int) $value;
                } elseif (is_float($value)) {
                    $value = (float) $value;
                } else {
                    $value = (double) $value;
                }
            }

            if (is_string($key)) {
                $pdo_statement->bindValue(':' . $key, $value, $param);
            } else {
                $pdo_statement->bindValue($key + 1, $value, $param);
            }
        }

        return $pdo_statement;
    }
267460
private function translateRecordIntoEventMessage(array $record)
    {
        $identifier = new MessageIdentifier($record['event_id']);

        $payload = $this->eventSerializer->deserializePayload(
            $record['event_payload'],
            Contract::createFromClassName($record['event_payload_type'])
        );

        $metadata = $this->eventSerializer->deserializeMetadata(
            $record['event_metadata'],
            Contract::createFromClassName($record['event_metadata_type'])
        );

        $sequenceNumber = (int) $record['aggregate_version'];

        $eventMessage = new GenericEvent($this->aggregateRootIdentifier, $sequenceNumber, $identifier, $payload, $metadata);

        return $eventMessage;
    }
134443
public static function update_category(stdClass $record) {
        $category = new category($record->id);
        $category->from_record($record);

        $result = $category->update();

        return $category;
    }
432611
public function saveInto(DataObjectInterface $record)
    {
        if ($this->name) {
            $record->setCastedField($this->name, $this->dataValue());
        }
    }
1105391
public function populateIndex(BulkOperation $bulk, databox $databox)
    {
        $this->logger->info(sprintf('Indexing database %s...', $databox->get_viewname()));

        $submitted_records = [];
        // No delegate, scan all records
        $fetcher = $this->fetcherFactory->createFetcher($databox);

        // post fetch : flag records as "indexing"
        $fetcher->setPostFetch(function(array $records) use ($databox, $fetcher) {
            RecordQueuer::didStartIndexingRecords($records, $databox);
            // do not restart the fetcher since it has no clause on jetons
        });

        // bulk flush : flag records as "indexed"
        $bulk->onFlush(function($operation_identifiers) use ($databox, &$submitted_records) {
            $this->onBulkFlush($databox, $operation_identifiers, $submitted_records);
        });

        // Perform indexing
        $this->indexFromFetcher($bulk, $fetcher, $submitted_records);

        $this->logger->info(sprintf('Finished indexing %s', $databox->get_viewname()));
    }
465422
protected function write(array $record): void
    {
        if (!$this->isWebRequest()) {
            return;
        }

        self::$json['rows'][] = $record['formatted'];

        $this->send();
    }
1027480
public function updateRecord(int $recordID, array $data)
    {
        foreach ($this->getRecords() as $key => $record) {
            if ($recordID == $record[$this->primaryKey]) {
                foreach ($data as $dataKey => $dataValue) {
                    if (isset($record[$dataKey])) {
                        $record[$dataKey] = $dataValue;
                    }
                }

                $this->database->getReference()
                    ->getChild($this->table)
                    ->getChild($key)
                    ->set($record);
            }
        }

        return $this->getRecord($recordID);
    }
568670
protected function update($dataobject) {
        global $DB;
        $updatereferencesneeded = false;
        $updatemimetype = false;
        $keys = array_keys((array)$this->file_record);
        $filepreupdate = clone($this->file_record);
        foreach ($dataobject as $field => $value) {
            if (in_array($field, $keys)) {
                if ($field == 'contextid' and (!is_number($value) or $value < 1)) {
                    throw new file_exception('storedfileproblem', 'Invalid contextid');
                }

                if ($field == 'component') {
                    $value = clean_param($value, PARAM_COMPONENT);
                    if (empty($value)) {
                        throw new file_exception('storedfileproblem', 'Invalid component');
                    }
                }

                if ($field == 'filearea') {
                    $value = clean_param($value, PARAM_AREA);
                    if (empty($value)) {
                        throw new file_exception('storedfileproblem', 'Invalid filearea');
                    }
                }

                if ($field == 'itemid' and (!is_number($value) or $value < 0)) {
                    throw new file_exception('storedfileproblem', 'Invalid itemid');
                }


                if ($field == 'filepath') {
                    $value = clean_param($value, PARAM_PATH);
                    if (strpos($value, '/') !== 0 or strrpos($value, '/') !== strlen($value)-1) {
                        // path must start and end with '/'
                        throw new file_exception('storedfileproblem', 'Invalid file path');
                    }
                }

                if ($field == 'filename') {
                    // folder has filename == '.', so we pass this
                    if ($value != '.') {
                        $value = clean_param($value, PARAM_FILE);
                    }
                    if ($value === '') {
                        throw new file_exception('storedfileproblem', 'Invalid file name');
                    }
                }

                if ($field === 'timecreated' or $field === 'timemodified') {
                    if (!is_number($value)) {
                        throw new file_exception('storedfileproblem', 'Invalid timestamp');
                    }
                    if ($value < 0) {
                        $value = 0;
                    }
                }

                if ($field === 'referencefileid') {
                    if (!is_null($value) and !is_number($value)) {
                        throw new file_exception('storedfileproblem', 'Invalid reference info');
                    }
                }

                if (($field == 'contenthash' || $field == 'filesize') && $this->file_record->$field != $value) {
                    $updatereferencesneeded = true;
                }

                if ($updatereferencesneeded || ($field === 'filename' && $this->file_record->filename != $value)) {
                    $updatemimetype = true;
                }

                // adding the field
                $this->file_record->$field = $value;
            } else {
                throw new coding_exception("Invalid field name, $field doesn't exist in file record");
            }
        }
        // Validate mimetype field
        if ($updatemimetype) {
            $mimetype = $this->filesystem->mimetype_from_storedfile($this);
            $this->file_record->mimetype = $mimetype;
        }

        $DB->update_record('files', $this->file_record);
        if ($updatereferencesneeded) {
            // Either filesize or contenthash of this file have changed. Update all files that reference to it.
            $this->fs->update_references_to_storedfile($this);
        }

        // Callback for file update.
        if (!$this->is_directory()) {
            if ($pluginsfunction = get_plugins_with_function('after_file_updated')) {
                foreach ($pluginsfunction as $plugintype => $plugins) {
                    foreach ($plugins as $pluginfunction) {
                        $pluginfunction($this->file_record, $filepreupdate);
                    }
                }
            }
        }
    }
820654
protected function write(array $record)
    {
        $chat_id = $this->bot->getChatLog();
        // Check chat_id is valid
        if ($chat_id !== "") {
            $this->bot->withChatId($chat_id, 'sendMessage', $record['message']);
        }
    }
691123
private function listDataboxTerms(\databox $databox)
    {
        $ret = [];
        foreach ($databox->get_cgus() as $locale => $array_terms) {
            $ret[] = ['locale' => $locale, 'terms' => $array_terms['value']];
        }

        return $ret;
    }
375030
public function set_data($datavalue, $datakey = null) {
        $this->datavalue = $datavalue;

        // We must clear the datakey when changing the datavalue.
        $this->set_data_key($datakey);
    }
804928
public static function update_purpose(stdClass $record) {
        if (!isset($record->sensitivedatareasons)) {
            $record->sensitivedatareasons = '';
        }

        $purpose = new purpose($record->id);
        $purpose->from_record($record);

        $result = $purpose->update();

        return $purpose;
    }
132366
protected function transformRecord($record)
    {
        $columnNames = $this->columnManager->getRequestedColumnNames();
        $columnNames->transform(function ($item) use ($record) {
            return $this->getColumnValue($item, $record);
        });

        $datatableParameters = $this->getDatatableParameters($record);

        return array_merge($datatableParameters, $columnNames->toArray());
    }
1365933
public function addBindingsToStatement(PDOStatement $stmt, array $bindings)
    {
        foreach ($bindings as $key => &$binding) {
            $value  = &$binding;
            $type   = PDO::PARAM_STR;
            $length = -1;

            if (is_array($binding)) {
                $value  = &$binding['value'];
                $type   = array_key_exists('type', $binding) ? $binding['type'] : PDO::PARAM_STR;
                $length = array_key_exists('length', $binding) ? $binding['length'] : -1;
            }

            $stmt->bindParam(':' . $key, $value, $type, $length);
        }

        return $stmt;
    }
605174
public function write_record($record, $rownum) {
        if ($this->sheetdatadded) {
            echo ",";
        }

        echo json_encode($record);

        $this->sheetdatadded = true;
    }
1250362
public function update($table = '', $data = [], $arrayWhere = [], $other = '')
    {
        // if table name is empty
        if (!empty($table)) {
            // check if array data and where array is more then 0
            if (count($data) > 0 && count($arrayWhere) > 0) {
                // parse array data and make a temp array
                $tmp = [];
                foreach ($data as $k => $v) {
                    $tmp[] = "$k = :s_$k";
                }
                // join temp array value with ,
                $sFields = implode(', ', $tmp);
                // delete temp array from memory
                unset($tmp);

                $tmp = [];
                // parse where array and store in temp array
                foreach ($arrayWhere as $k => $v) {
                    $tmp[] = "$k = :s_$k";
                }

                $this->data = $data;
                $this->arrayWhere = $arrayWhere;
                // join where array value with AND operator and create where condition
                $where = implode(' AND ', $tmp);
                // unset temp array
                unset($tmp);
                // make sql query to update
                $this->sql = "UPDATE `$table` SET $sFields WHERE $where $other;";
                // on PDO prepare statement
                $this->STH = $this->prepare($this->sql);
                // bind pdo param for update statement
                $this->_bindPdoNameSpace($data);
                // bind pdo param for where clause
                $this->_bindPdoNameSpace($arrayWhere);
                // try catch block start
                try {
                    // if PDO run
                    if ($this->STH->execute()) {
                        // get affected rows
                        $this->affectedRows = $this->STH->rowCount();
                        // close PDO
                        $this->STH->closeCursor();
                        // return self object
                        return $this;
                    } else {
                        self::error($this->STH->errorInfo());
                    }
                } catch (\PDOException $e) {
                    // get pdo error and pass on error method
                    self::error($e->getMessage() . ': ' . __LINE__);
                } // try catch block end
            } else {
                self::error('update statement not in valid format..');
            }
        } else {
            self::error('Table name not found..');
        }
    }