Apply attribution if we accepted the lead.

@throws \Exception
480589
public function applyAttribution()
    {
        if ($this->valid && $this->cost && Stat::TYPE_ACCEPTED === $this->status) {
            // check if an id exists and attribution field exists b/c sometimes its not a well-formed entity
            if ($this->contact->getId() && !property_exists($this->contact, 'attribution')) {
                $this->contact = $this->contactModel->getEntity($this->contact->getId());
            }
            $originalAttribution = $this->contact->getAttribution();
            // Attribution is always a negative number to represent cost.
            $this->attribution = ($this->cost * -1);
            $this->contact->addUpdatedField(
                'attribution',
                $originalAttribution + $this->attribution,
                $originalAttribution
            );
            $this->dispatchContextCreate();

            if (!$this->imported) {
                // contacts imported via file upload hit this method via a pre-save event so dont save here.
                $this->contactModel->saveEntity($this->contact);
            }
        }
    }
1175215
public function actionApprove()
	{
		if(Yii::app()->request->isPostRequest)
		{
			$comment=$this->loadModel();
			$comment->approve();
			$this->redirect(array('index'));
		}
		else
			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
	}
1310570
public function onKernelTerminate()
    {
        foreach ($this->managers as $key => $value) {
            if ($value['force_commit']) {
                try {
                    /** @var Manager $manager */
                    $manager = $this->container->get(sprintf('es.manager.%s', $key));
                } catch (\Exception $e) {
                    continue;
                }
                $manager->commit();
            }
        }
    }
897421
public function accept()
    {
        $filename = $this->current()->getRelativePathname();

        if ('\\' === \DIRECTORY_SEPARATOR) {
            $filename = str_replace('\\', '/', $filename);
        }

        return $this->isAccepted($filename);
    }
432165
public function afterMemberLoggedIn()
    {
        if ($this->owner->GUID) {
            try {
                Injector::inst()->get(LDAPService::class)->updateMemberFromLDAP($this->owner);
            } catch (Exception $e) {
                // If the failure is acceptable, then ignore it and return. Otherwise, re-throw the exception
                if ($this->owner->config()->get('allow_update_failure_during_login')) {
                    return;
                }
                throw $e;
            }
        }
    }
1082532
public function commit()
    {
        if (!$this->getIsActive()) {
            throw new Exception('Failed to commit transaction: transaction was inactive.');
        }

        $this->_level--;
        if ($this->_level === 0) {
            Log::debug('Commit transaction' . __METHOD__);
            $this->db->pdo->commit();
            $this->db->trigger(Connection::EVENT_COMMIT_TRANSACTION);
            return;
        }

        $schema = $this->db->getSchema();
        if ($schema->supportsSavepoint()) {
            Log::debug('Release savepoint ' . $this->_level . __METHOD__);
            $schema->releaseSavepoint('LEVEL' . $this->_level);
        } else {
            Log::info('Transaction not committed: nested transaction not supported' . __METHOD__);
        }
    }
226774
function attributionsContent( $attributions ) {
		$media_attributions = '';
		$html = '';
		$licensing = new Licensing();
		$supported = $licensing->getSupportedTypes();

		if ( $attributions ) {
			// generate appropriate markup for each field
			foreach ( $attributions as $attribution ) {

				// unset empty arrays
				$attribution = array_filter( $attribution, 'strlen' );

				// only process if non-empty
				if ( count( $attribution ) > 0 ) {
					$author_byline = isset( $attribution['author'] ) ? __( ' by ', 'pressbooks' ) : '';
					$adapted_byline = isset( $attribution['adapted'] ) ? __( ' adapted by ', 'pressbooks' ) : '';
					$license_prefix = isset( $attribution['license'] ) ? ' &copy; ' : '';
					$author = isset( $attribution['author'] ) ? $attribution['author'] : '';
					$title = isset( $attribution['title'] ) ? $attribution['title'] : '';
					$adapted_author = isset( $attribution['adapted'] ) ? $attribution['adapted'] : '';

					$media_attributions .= sprintf(
						'<li %1$s>%2$s %3$s %4$s %5$s</li>',
						// about attribute
						( isset( $attribution['title_url'] ) ) ?
							sprintf(
								'about="%s"',
								$attribution['title_url']
							) : '',
						// title attribution
						( isset( $attribution['title_url'] ) ) ?
							sprintf(
								'<a rel="cc:attributionURL" href="%1$s" property="dc:title">%2$s</a>',
								$attribution['title_url'],
								$title
							) : $title,
						// author attribution
						sprintf(
							'%1$s %2$s',
							$author_byline,
							( isset( $attribution['author_url'] ) ) ?
								sprintf(
									'<a rel="dc:creator" href="%1$s" property="cc:attributionName">%2$s</a>',
									$attribution['author_url'],
									$author
								) : $author
						),
						// adapted attribution
						sprintf(
							'%1$s %2$s',
							$adapted_byline,
							( isset( $attribution['adapted_url'] ) ) ?
								sprintf(
									'<a rel="dc:source" href="%1$s">%2$s</a>',
									$attribution['adapted_url'],
									$adapted_author
								) : $adapted_author
						),
						// license attribution
						sprintf(
							'%1$s %2$s',
							$license_prefix,
							( isset( $attribution['license'] ) ) ?
								sprintf(
									'<a rel="license" href="%1$s">%2$s</a>',
									$licensing->getUrlForLicense( $attribution['license'] ),
									$supported[ $attribution['license'] ]['desc']
								) : ''
						)
					);
				}
			}
			if ( ! empty( $media_attributions ) ) {
				$html = sprintf(
					'<div class="media-atttributions" prefix:cc="http://creativecommons.org/ns#" prefix:dc="http://purl.org/dc/terms/"><h3>' . __( 'Media Attributions', 'pressbooks' ) . '</h3><ul>%s</ul></div>',
					$media_attributions
				);
			}
		}

		return $html;
	}
619180
public function run()
    {
        DB::beginTransaction();
        try {
            $this->down();
            $this->addNotification([
                'category' => 'default',
                'severity' => 'high',
                'type'     => 'email',
                'event'    => 'email.sample-module-notification',
                'contents' => [
                    'en' => [
                        'title'   => 'Sample Email Template',
                        'content' => file_get_contents(__DIR__ . '/../../views/notification/module_sample_notification.twig')
                    ],
                ]
            ]);
        } catch (Exception $ex) {
            DB::rollback();
            throw $ex;
        }

        DB::commit();
    }
667096
public function validateAcceptHeader(): void
    {
        if ($this->isValidMediaTypeHeader("accept") === false) {
            throw $this->exceptionFactory->createMediaTypeUnacceptableException($this, $this->getHeaderLine("accept"));
        }
    }
577748
public function commit()
    {
        if ($this->rollbackAgain) {
            throw new \wf\db\Exception('Please throw exception after rollback in last catch block');
        }

        --$this->transactions;
    
        if($this->transactions == 0 && false === $this->dbh->commit()) {
            throw new \wf\db\Exception('transaction commit error: ' . $this->getLastErr());
        }

        if ($this->transactions < 0) {
            $this->transactions = 0;
        }
    }
1048899
public function addException($exception)
    {
        if ($exception->getMessage()) {
            $this->message .= "\n".$exception->getMessage();
        }

        $this->exceptions[] = $exception;
    }
1186967
public function checkRequirements()
    {
        $process = new Process($this->getBin().' version');
        $process->run();

        if (!$process->isSuccessful()) {
            throw new Exception('compass is not found at '.$this->getBin().'. '.$process->getErrorOutput());
        }
    }
1261741
public function apply()
    {
        $this->backup = $this->property->getValue();
        $this->property->setValue($this->value);
    }
501866
public function onBeforeWrite()
    {
        if (!isset(self::$localizedFields[$this->ownerBaseClass])) {
            return;
        }

        $fields = self::$localizedFields[$this->ownerBaseClass];
        foreach ($fields as $field => $localized) {
            foreach (self::get_target_locales() as $locale) {
                $fieldName = self::localized_field($field, $locale);
                if ($this->owner->isChanged($fieldName, 2) && !$this->canTranslate(null, $locale)) {
                    throw new PermissionFailureException(
                        "You're not allowed to edit the locale '$locale' for this object");
                }
            }
        }
    }
1347437
public function report(Exception $exception)
    {
        $enableEmailExceptions = config('exceptions.emailExceptionEnabled');

        if ($enableEmailExceptions === '') {
            $enableEmailExceptions = config('exceptions.emailExceptionEnabledDefault');
        }

        if ($enableEmailExceptions) {
            if ($this->shouldReport($exception)) {
                $this->sendEmail($exception);
            }
        }

        parent::report($exception);
    }
102927
private function updateEcho()
    {
        $this->isEcho = (!is_null(Helper::array_find($this->_message, 'is_echo')));
        if ($this->isEcho) {
            if (isset($this->message)) {
                $this->message->app_id = Helper::array_find($this->_message, 'app_id');
                $this->message->metadata = Helper::array_find($this->_message, 'metadata');
                $this->message->mid = Helper::array_find($this->_message, 'mid');
                $this->message->seq = Helper::array_find($this->_message, 'seq');
            } else
                throw new \Exception('Message not yet created for Echo');
        }
    }
585352
public function toBe()
    {
        if (!is_string($this->_actual)) {
            throw new Exception("Error `toBe()` need to be applied on a fully-namespaced class or function name.");
        }
        $method = Monkey::patch($this->_actual);
        call_user_func_array([$method, 'toBe'], func_get_args());
    }