更新数组

@param array $aData
@param array $aUpdate
@param string $sPath
@static
@access public
@return array
328095
public static function _update(array $aData, array $aUpdate, $sPath = '') {

		foreach ($aUpdate as $sKey => $mVal) {

			// key 里不能带 $ 和 . 这两个特殊符号
			if (strpos($sKey, '$') !== FALSE || strpos($sKey, '.') !== FALSE) {
				throw new TangoException('illegal characters in key = "' . self::_path($sPath, $sKey) . '"');
			}

			$mCurrent =& $aData[$sKey];

			// 没有老值，直接赋新值
			if ($mCurrent === NULL) {
				if (is_array($mVal) && !self::checkKey($mVal)) {
					throw new TangoException('array not match when updating path = "' . self::_path($sPath, $sKey) . '"');
				}
				$mCurrent = $mVal;
				continue;
			}

			$bArray = is_array($mVal);

			// 如果一个是 array 而另外一个不是，报错
			if ($bArray != is_array($mCurrent)) {
				throw new TangoException('array not match when updating path = "' . self::_path($sPath, $sKey) . '"');
			}

			// 如果是数组，则走递归
			if ($bArray) {
				$aData[$sKey] = self::_update($aData[$sKey], $mVal, self::_path($sPath, $sKey));
				continue;
			}

			// 如果上述情况都不存在，直接赋值
			$aData[$sKey] = $mVal;
		}

		return $aData;
	}
398797
public function addAuth(array $auth, $validate = false)
    {
        $response = $this->getUser()->post(
            'source/auth/add',
            array('id' => $this->getId(), 'auth' => $auth, 'validate' => $validate)
        );

        $this->auth = $response['auth'];
    }
103345
public function create(array $aData = [], $bReturnObject = false)
    {
        try {

            if (empty($aData['organisation']) && empty($aData['first_name']) && empty($aData['last_name'])) {
                throw new InvoiceException('"organisation", "first_name" or "last_name" must be supplied.', 1);
            }

            //  Compile the label
            $aData['label'] = $this->compileLabel($aData);

            return parent::create($aData, $bReturnObject);

        } catch (\Exception $e) {
            $this->setError($e->getMessage());
            return false;
        }
    }
1135331
public function execute($aData = [])
    {
        $oDb        = Factory::service('Database');
        $oUserModel = Factory::model('User', 'nails/module-auth');
        $oResponse  = Factory::factory('DataExportSourceResponse', 'nails/module-admin');

        $oSource = $oDb
            ->select('u.id, u.first_name, u.last_name, ue.email')
            ->join(NAILS_DB_PREFIX . 'user_email ue', 'u.id = ue.user_id AND ue.is_primary = 1', 'LEFT')
            ->get($oUserModel->getTableName() . ' u');

        return $oResponse
            ->setLabel($this->getLabel())
            ->setFileName($this->getFileName())
            ->setFields(['id', 'first_name', 'last_name', 'email'])
            ->setSource($oSource);
    }
79758
public function updateAttributes($index, array $attrs, array $values, $mva = false)
    {
        // verify everything
        assert(is_string($index));
        assert(is_bool($mva));

        assert(is_array($attrs));
        foreach ($attrs as $attr) {
            assert(is_string($attr));
        }

        assert(is_array($values));
        foreach ($values as $id => $entry) {
            assert(is_numeric($id));
            assert(is_array($entry));
            assert(count($entry) == count($attrs));
            foreach ($entry as $v) {
                if ($mva) {
                    assert(is_array($v));
                    foreach ($v as $vv) {
                        assert(is_int($vv));
                    }
                } else {
                    assert(is_int($v));
                }
            }
        }

        // build request
        $this->_MBPush();
        $req = pack('N', strlen($index)).$index;

        $req .= pack('N', count($attrs));
        foreach ($attrs as $attr) {
            $req .= pack('N', strlen($attr)).$attr;
            $req .= pack('N', $mva ? 1 : 0);
        }

        $req .= pack('N', count($values));
        foreach ($values as $id => $entry) {
            $req .= $this->sphPackU64($id);
            foreach ($entry as $v) {
                $req .= pack('N', $mva ? count($v) : $v);
                if ($mva) {
                    foreach ($v as $vv) {
                        $req .= pack('N', $vv);
                    }
                }
            }
        }

        // connect, send query, get response
        if (!($fp = $this->_Connect())) {
            $this->_MBPop();

            return -1;
        }

        $len = strlen($req);
        $req = pack('nnN', SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len).$req; // add header
        if (!$this->_Send($fp, $req, $len + 8)) {
            $this->_MBPop();

            return -1;
        }

        if (!($response = $this->_GetResponse($fp, VER_COMMAND_UPDATE))) {
            $this->_MBPop();

            return -1;
        }

        // parse response
        list(, $updated) = unpack('N*', substr($response, 0, 4));
        $this->_MBPop();

        return $updated;
    }
259636
protected function formatObject(
        &$oObj,
        array $aData = [],
        array $aIntegers = [],
        array $aBools = [],
        array $aFloats = []
    ) {

        $aBools[] = 'has_captcha';

        parent::formatObject($oObj, $aData, $aIntegers, $aBools, $aFloats);
    }
1070388
public function update($iPaymentId, array $aData = []): bool
    {
        $oDb = Factory::service('Database');

        try {

            $oDb->trans_begin();

            unset($aData['ref']);
            unset($aData['token']);

            if (array_key_exists('custom_data', $aData)) {
                $aData['custom_data'] = json_encode($aData['custom_data']);
            }

            $bResult = parent::update($iPaymentId, $aData);

            if (!$bResult) {
                throw new PaymentException('Failed to update payment.');
            }

            $oDb->trans_commit();
            $this->triggerEvent(
                Events::PAYMENT_UPDATED,
                [$this->getPaymentForEvent($iPaymentId)]
            );

            return $bResult;

        } catch (\Exception $e) {
            $oDb->trans_rollback();
            $this->setError($e->getMessage());
            return false;
        }
    }
419207
public function setFailed($iRefundId, $aData = [])
    {
        $aData['status'] = self::STATUS_FAILED;
        return $this->update($iRefundId, $aData);
    }
457792
protected function setSession( $session_name, $arrData, $merge = false )
	{
	    if ($merge) 
	    {
	        $this->_session = \Session::getInstance()->get( $session_name );
	        
	        // numerische Schlüssel werden neu numeriert, daher
	        // geht nicht: array_merge($this->_session, $arrData)
	        $merge_array = (array)$this->_session + $arrData;
	        \Session::getInstance()->set( $session_name, $merge_array );
	    }
	    else 
	    {
	        \Session::getInstance()->set( $session_name, $arrData );
	    }
	    
	}
996367
protected function injectLocalisationQuery(array &$aData): void
    {
        /** @var Locale $oLocale */
        $oLocale = Factory::service('Locale');
        $sTable  = $this->getTableName();
        $sAlias  = $this->getTableAlias();

        /**
         * Restrict to a specific locale by passing in USE_LOCALE to the data array
         * Pass NO_LOCALISE_FILTER to the data array the developer can return items for all locales
         */

        if (!array_key_exists('select', $aData)) {
            $aData['select'] = [
                $sAlias . '.*',
            ];
        }

        if (array_key_exists('USE_LOCALE', $aData)) {
            if ($aData['USE_LOCALE'] instanceof \Nails\Common\Factory\Locale) {
                $oUserLocale = $aData['USE_LOCALE'];
            } else {
                list($sLanguage, $sRegion) = $oLocale::parseLocaleString($aData['USE_LOCALE']);
                $oUserLocale = $this->getLocale($sLanguage, $sRegion);
            }

            if (!array_key_exists('where', $aData)) {
                $aData['where'] = [];
            }

            $aData['where'][] = ['language', $oUserLocale->getLanguage()];
            $aData['where'][] = ['region', $oUserLocale->getRegion()];

        } elseif (!array_key_exists('NO_LOCALISE_FILTER', $aData)) {

            $oUserLocale      = $oLocale->get();
            $sUserLanguage    = $oUserLocale->getLanguage();
            $sUserRegion      = $oUserLocale->getRegion();
            $oDefaultLocale   = $oLocale->getDefautLocale();
            $sDefaultLanguage = $oDefaultLocale->getLanguage();
            $sDefaultRegion   = $oDefaultLocale->getRegion();

            $sQueryExact    = 'SELECT COUNT(*) FROM ' . $sTable . ' sub_1 WHERE sub_1.id = ' . $sAlias . '.id AND sub_1.' . static::$sColumnLanguage . ' = "' . $sUserLanguage . '" AND sub_1.' . static::$sColumnRegion . ' = "' . $sUserRegion . '"';
            $sQueryLanguage = 'SELECT COUNT(*) FROM ' . $sTable . ' sub_2 WHERE sub_2.id = ' . $sAlias . '.id AND sub_2.' . static::$sColumnLanguage . ' = "' . $sUserLanguage . '" AND sub_2.' . static::$sColumnRegion . ' != "' . $sUserRegion . '"';


            if ($oLocale::MODEL_FALLBACK_TO_DEFAULT_LOCALE) {
                $aConditionals = [
                    '((' . $sQueryExact . ') = 1 AND ' . static::$sColumnLanguage . ' = "' . $sUserLanguage . '" AND ' . static::$sColumnRegion . ' = "' . $sUserRegion . '")',
                    '((' . $sQueryExact . ') = 0 AND ' . static::$sColumnLanguage . ' = "' . $sDefaultLanguage . '" AND ' . static::$sColumnRegion . ' = "' . $sDefaultRegion . '")',
                ];
            } else {
                $aConditionals = [
                    '((' . $sQueryExact . ') = 1 AND ' . static::$sColumnLanguage . ' = "' . $sUserLanguage . '" AND ' . static::$sColumnRegion . ' = "' . $sUserRegion . '")',
                    '((' . $sQueryExact . ') = 0 AND ' . static::$sColumnLanguage . ' = "' . $sUserLanguage . '")',
                    '((' . $sQueryExact . ') = 0 AND (' . $sQueryLanguage . ') = 0 AND ' . static::$sColumnLanguage . ' = "' . $sDefaultLanguage . '" AND ' . static::$sColumnRegion . ' = "' . $sDefaultRegion . '")',
                ];
            }

            if (!array_key_exists('where', $aData)) {
                $aData['where'] = [];
            }

            $aData['where'][] = '(' . implode(' OR ', $aConditionals) . ')';
        }

        //  Ensure each row knows about the other items available
        $sQuery = 'SELECT GROUP_CONCAT(CONCAT(`others`.`language`, \'_\', `others`.`region`)) FROM ' . $sTable . ' `others` WHERE `others`.`id` = `' . $sAlias . '`.`id`';
        if (!$this->isDestructiveDelete()) {
            $sQuery .= ' AND `others`.`' . $this->getColumn('deleted') . '` = 0';
        }
        $aData['select'][] = '(' . $sQuery . ') available_locales';
    }
978361
public function save($sPath, $sFilename)
    {
        if (!is_writable($sPath)) {
            $this->setError('Cannot write to ' . $sPath);
            return false;
        }

        $this->oDomPdf->render();
        $bResult = (bool) file_put_contents(
            rtrim($sPath, '/') . '/' . $sFilename,
            $this->oDomPdf->output()
        );

        $this->reset();

        return $bResult;
    }
916227
public function update(array $data)
    {
        $where = [];
        $options = $this->parseExpress();
        $data    = array_merge($options['data'], $data);
        if (isset($options['cache']) && is_string($options['cache']['key'])) {
            $key = $options['cache']['key'];
        }
        $pk = $this->getPk();
        if (empty($options['where'])) {
            // 如果存在主键数据 则自动作为更新条件
            if (is_string($pk) && isset($data[$pk])) {
                $where[$pk] = $data[$pk];
                $key        = 'mongo:' . $options['table'] . '|' . $data[$pk];
                unset($data[$pk]);
            } elseif (is_array($pk)) {
                // 增加复合主键支持
                foreach ($pk as $field) {
                    if (isset($data[$field])) {
                        $where[$field] = $data[$field];
                    } else {
                        // 如果缺少复合主键数据则不执行
                        throw new Exception('miss complex primary data');
                    }
                    unset($data[$field]);
                }
            }
            if (!isset($where)) {
                // 如果没有任何更新条件则不执行
                throw new Exception('miss update condition');
            } else {
                $options['where']['$and'] = $where;
            }
        } elseif (!isset($key) && is_string($pk) && isset($options['where']['$and'][$pk])) {
            $key = $this->getCacheKey($options['where']['$and'][$pk], $options);
        }

        // 生成bulkWrite对象
        $bulk         = $this->builder->update($data, $options);
        $writeConcern = isset($options['writeConcern']) ? $options['writeConcern'] : null;
        $writeResult  = $this->execute($options['table'], $bulk, $writeConcern);

        $result = $writeResult->getModifiedCount();
        if ($result) {
            if (isset($where[$pk])) {
                $data[$pk] = $where[$pk];
            } elseif (is_string($pk) && isset($key) && strpos($key, '|')) {
                list($a, $val) = explode('|', $key);
                unset($a);
                $data[$pk]     = $val;
            }
            $options['data'] = $data;
            $this->trigger('after_update', $options);
        }
        return $result;
    }
935132
public function setPending($iRefundId, $aData = [])
    {
        $aData['status'] = self::STATUS_PENDING;
        return $this->update($iRefundId, $aData);
    }
147701
protected function saveToDb(array $aData, int $iId = null): bool
    {
        $oDb = Factory::service('Database');

        if (!empty($aData)) {
            if (!classUses($this, Localised::class)) {
                unset($aData['id']);
            }
            foreach ($aData as $sColumn => $mValue) {
                if (is_array($mValue)) {
                    $mSetValue = isset($mValue[0]) ? $mValue[0] : null;
                    $bEscape   = isset($mValue[1]) ? (bool) $mValue[1] : true;
                    $oDb->set($sColumn, $mSetValue, $bEscape);
                } else {
                    $oDb->set($sColumn, $mValue);
                }
            }
        }

        if (!$iId) {
            $oDb->insert($this->getTableName());
            return (bool) $oDb->affected_rows();
        } else {
            $oDb->where('id', $iId);
            return $oDb->update($this->getTableName());
        }
    }
855379
public function update(array $data = [])
    {
        $options = $this->parseExpress();
        $data    = array_merge($options['data'], $data);
        $pk      = $this->getPk($options);
        $where   = [];
        if (isset($options['cache']) && is_string($options['cache']['key'])) {
            $key = $options['cache']['key'];
        }

        if (empty($options['where'])) {
            // 如果存在主键数据 则自动作为更新条件
            if (is_string($pk) && isset($data[$pk])) {
                $where[$pk] = $data[$pk];
                if (!isset($key)) {
                    $key = 'think:' . $options['table'] . '|' . $data[$pk];
                }
                unset($data[$pk]);
            } elseif (is_array($pk)) {
                // 增加复合主键支持
                foreach ($pk as $field) {
                    if (isset($data[$field])) {
                        $where[$field] = $data[$field];
                    } else {
                        // 如果缺少复合主键数据则不执行
                        throw new Exception('miss complex primary data');
                    }
                    unset($data[$field]);
                }
            }
            if (!isset($where)) {
                // 如果没有任何更新条件则不执行
                throw new Exception('miss update condition');
            } else {
                $options['where']['AND'] = $where;
            }
        } elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
            $key = $this->getCacheKey($options['where']['AND'][$pk], $options, $this->bind);
        }

        //过滤无效字段
        $this->filter($data);

        // 生成UPDATE SQL语句
        $sql = $this->builder->update($data, $options);
        // 获取参数绑定
        $bind = $this->getBind();
        if ($options['fetch_sql']) {
            // 获取实际执行的SQL语句
            return $this->connection->getRealSql($sql, $bind);
        } else {
            // 执行操作
            $result = '' == $sql ? 0 : $this->execute($sql, $bind);
            if ($result) {
                if (is_string($pk) && isset($where[$pk])) {
                    $data[$pk] = $where[$pk];
                } elseif (is_string($pk) && isset($key) && strpos($key, '|')) {
                    list($a, $val) = explode('|', $key);
                    unset($a);
                    $data[$pk]     = $val;
                }
                $options['data'] = $data;
                $this->trigger('after_update', $options);
            }
            return $result;
        }
    }
1102382
public function update($iId, $aData)
    {
        $aCategoryData = array();

        // --------------------------------------------------------------------------

        //  Some basic sanity testing
        if (empty($aData['label'])) {

            $this->setError('"label" is a required field.');
            return false;

        } else {

            $aCategoryData['label'] = trim($aData['label']);
        }

        // --------------------------------------------------------------------------

        $aCategoryData['slug'] = $this->generateSlug($aData['label'], $iId);

        if (isset($aData['description'])) {

            $aCategoryData['description'] = $aData['description'];
        }

        if (isset($aData['seo_title'])) {

            $aCategoryData['seo_title'] = strip_tags($aData['seo_title']);
        }

        if (isset($aData['seo_description'])) {

            $aCategoryData['seo_description'] = strip_tags($aData['seo_description']);
        }

        if (isset($aData['seo_keywords'])) {

            $aCategoryData['seo_keywords'] = strip_tags($aData['seo_keywords']);
        }

        return parent::update($iId, $aCategoryData);
    }
946646
public static function update($arr, $condition=null, $params=[]) {
        return static::dao()->update(
            $arr,
            $condition,
            $params
        );
    }