Save record to database.

@param string $origin
@param string|null $short

@return mixed
519993
protected function save($origin, $short = null)
    {
        $shortener = Shortener::updateOrCreate(
            ['hash' => hash('sha512', $origin)],
            ['url' => $origin, 'short' => $short]
        );

        return $shortener->exists ? $shortener->getKey() : false;
    }
102560
protected function saveSslRecord($domain, $result)
    {
        $record['grade'] = $result['results']['grade'];
        $record['results_url'] = 'https://www.htbridge.com/ssl/?id=' . $result['internals']['short_id'];

        if (isset($result['certificates']['information'][0])) {
            $record['valid'] = $result['certificates']['information'][0]['valid_now'];
            $record['valid_from'] = $result['certificates']['information'][0]['valid_from'];
            $record['valid_to'] = $result['certificates']['information'][0]['valid_to'];
            $record['revoked'] = $result['certificates']['information'][0]['revoked'];
            $record['expires_soon'] = $result['certificates']['information'][0]['expires_soon'];
            $record['issuer'] = $result['certificates']['information'][0]['issuer_cn'];
        }

        try {
            History::where('meta', $domain)->delete();
            History::create(['type' => 'ssl', 'meta' => $domain, 'record' => $record]);
        } catch (Exception $e) {
            $this->eye->logger()->error('Ssl record save failed', $e, $domain);
            throw $e;
        }
    }
73433
private function writeToFile($file, $content, $origin = 'n/a')
    {
        return file_put_contents($file, $this->getFileSignature($origin) . $content);
    }
1172323
public function save() {
        $this->invoke(self::BEFORE_SAVE, [$this]);
        if ($this->isNewRecord) {
            $row = $this->insert();
        } else {
            $row = $this->update();
        }
        $this->invoke(self::BEFORE_SAVE, [$this]);
        return $row;
    }
1369852
public function setShort($short)
    {
        $short = (string) $short;
        $this->short = function_exists('mb_substr')
            ? mb_substr($short, 0, 1)
            : substr($short, 0, 1)
        ;
        return $this;
    }
468012
protected function createSignatureToken($origin, \DateTime $expiration = null)
    {
        if (is_null($expiration)) {
            $expiration = new \DateTime('+ 1 hours');
        }

        $signer = new ES256();
        $privateKey = new Key('file://'.$this->getParameter('privateKey'));

        $builder = new Builder();
        $token = $builder
            ->setAudience($origin)
            ->setExpiration($expiration->getTimestamp())
            ->sign($signer, $privateKey)
            ->getToken();

        return $token;
    }
464384
public function get_details($short = '') {
        global $DB, $OUTPUT;
        $output = array();
        foreach ($this->params as $p) {
            $cohortname = $DB->get_field('cohort', 'name', array('id' => $p['cohort']));
            if (!$cohortname) {
                $str = $OUTPUT->error_text(get_string('error:nosuchcohort', 'badges'));
            } else {
                $str = html_writer::tag('b', '"' . format_string($cohortname, true) . '"');
            }
            $output[] = $str;
        }

        if ($short) {
            return implode(', ', $output);
        } else {
            return html_writer::alist($output, array(), 'ul');
        }
    }
872294
function save($parent_id = 0, $requestedSaveId = null, $createDefinition = true)
    {
        if ('' == trim($this->getTitle())) {
            throw new Exception('Must have a non blank title to save ' . $this->getType());
        }
        $levelId = $this->findEntityIdByTitle();
        if ($levelId) {
            $this->id = $levelId;
            return $levelId;
        }
        if ($requestedSaveId && $this->requestedIdCorrespondsToExistingRecord($requestedSaveId)) {
            $this->id = $requestedSaveId;
        }
        if ($this->getId()) {
            $sql = sprintf(
                "UPDATE %s SET `title` = %s WHERE id = %d",
                $this->getReadAdapter()->quoteIdentifier($this->getTable()),
                $this->getReadAdapter()->quote($this->getTitle()),
                (int)$this->getId()
            );
            $this->query($sql);
            return $this->id;
        }
        $data = array('title' => $this->getTitle());
        if ($requestedSaveId) {
            $data['id'] = $requestedSaveId;
        }
        $this->getReadAdapter()->insert($this->getTable(), $data);
        $levelId = $this->getReadAdapter()->lastInsertId();
        $this->setId($levelId);
        return $levelId;
    }
487491
private static function serialiseOrigin($origin)
    {
        if (!is_array($origin)) {
            $result = 'null';
        } else {
            $result = $origin[0] . '://' . lib\HostProcessing::serializeHost($origin[1]);
            if (isset(lib\URL::$specialSchemes[$origin[0]]) && $origin[2] !== lib\URL::$specialSchemes[$origin[0]]) {
                $result .= ':' . $origin[2];
            }
        }
        return $result;
    }
474489
public function Link($short = false)
    {
        if ($this->getIsDefaultEntity()) {
            $base = Controller::join_links(
                Director::baseURL(),
                Config::inst()->get('DocumentationViewer', 'link_base'),
                $this->getLanguage(),
                '/'
            );
        } else {
            $base = Controller::join_links(
                Director::baseURL(),
                Config::inst()->get('DocumentationViewer', 'link_base'),
                $this->getLanguage(),
                $this->getKey(),
                '/'
            );
        }

        if ($short && $this->stable) {
            return $base;
        }

        return Controller::join_links(
            $base,
            $this->getVersion(),
            '/'
        );
    }
1102851
function preSave($create = false)
    {
        if ($this->id == '') {
            $this->creation_dtime = gmdate('Y-m-d H:i:s');
        }
        $this->modif_dtime = gmdate('Y-m-d H:i:s');
        // File path
        $path = $this->getAbsloutPath();
        // file size
        if (file_exists($path)) {
            $this->file_size = filesize($path);
        } else {
            $this->file_size = 0;
        }
        // mime type (based on file name)
        $mime_type = $this->mime_type;
        if (! isset($mime_type) || $mime_type === 'application/octet-stream') {
            $fileInfo = Pluf_FileUtil::getMimeType($this->file_name);
            $this->mime_type = $fileInfo[0];
        }
    }
777050
public function save($data = null, $return = Db::RETURN_ISOK)
	{
		if(null === $data)
		{
			$data = $this->data;
		}
		$table = $this->getOptionTable();
		if(empty($this->fields) || $table !== $this->tableName())
		{
			$this->loadFields($fields, $fieldNames, $pk, $bitFields, $table);
		}
		else
		{
			$pk = $this->pk;
		}
		$pk = explode(',', $pk);
		$isEdit = true;
		foreach($pk as $tpk)
		{
			if(!array_key_exists($tpk, $data))
			{
				$isEdit = false;
				break;
			}
		}
		// 判断记录是否存在，来决定$isEdit的值
		if($isEdit)
		{
			$option = $this->operationOption;
			$isEdit = $this->wherePk($data,$table)->count() > 0;
			$this->operationOption = $option;
		}
		// 2个if不要合并！
		if($isEdit)
		{
			$result = $this->wherePk($data,$table)->edit($data,$return);
			if(Db::RETURN_INSERT_ID === $result)
			{
				return $pk[0];
			}
			else
			{
				return $result;
			}
		}
		else
		{
			return $this->add($data);
		}
	}
147752
public function save($options)
    {
        $gcc = get_called_class();
        $class = $gcc::init();
        $cap = $this->_database->getCapsule();
        $params = (array) $options;
        $this->filter($params);

        return $cap->table($this->table)->update($params);
    }
281332
public static function exists($short)
    {
        // Check if language is restricted by domain middleware
        if (self::$__domain_restricted_languages && !in_array($short, self::$__domain_restricted_languages)) {
            return false;
        }

        // Try cache
        $cache_key = 'language_exists_' . $short;
        $res = NULL;
        if (Settings::isCacheEnabled()) {
            $res = Cacher::getInstance()
                ->getDefaultCacher()
                ->get($cache_key);
        }

        // Get from db
        if ($res === NULL) {
            $languages = new LanguageEntityRepository();
            $languages->setWhereShort($short);
            $res = (bool)$languages->getFirstObjectFromCollection();

            // Save in cache
            if (Settings::isCacheEnabled()) {
                Cacher::getInstance()
                    ->getDefaultCacher()
                    ->set($cache_key, $res);
            }
        }

        return $res;
    }
75518
public function save(Site $site)
    {
        $id = $site->getId();
        if ($id == 0) {
            return $this->getTableGateway()->insert($site->toArray());
        } elseif ($this->findById($id)) {
            return $this->getTableGateway()->update($site->toArray(), array("id" => $id));
        } else {
            return NULL;
        }
    }
114590
public function decode($short)
    {
        $ids = $this->hashids->decode($short);

        if (empty($ids)) {
            throw new \InvalidArgumentException;
        }

        return Shortener::findOrFail(reset($ids))->getAttribute('url');
    }
1047383
public static function convertShortFormType(?string $shortType): ?string
    {
        $mapping = [
            'choice' => ChoiceType::class,
            'string' => TextType::class,
            'entity' => EntityType::class,
            'date' => DateType::class,
            'datetime' => DateType::class,
            'text' => TextareaType::class,
            'number' => NumberType::class,
            'float' => NumberType::class,
            'integer' => IntegerType::class,
            'smallint' => IntegerType::class,
            'boolean' => CheckboxType::class,
            'bigint' => NumberType::class,
            'decimal' => NumberType::class,
            'guid' => TextType::class,
            'array' => TextareaType::class,
            'simple_array' => TextareaType::class,
            'json_array' => TextareaType::class,
        ];
        $type = $shortType;

        if (key_exists($shortType, $mapping)) {
            $type = $mapping[$shortType];
        }

        return $type;
    }