Skip to content

Commit

Permalink
Merge branch '3.x' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
octoberapp committed Aug 7, 2024
2 parents cd5835b + 876bcb5 commit cbd822a
Show file tree
Hide file tree
Showing 20 changed files with 219 additions and 85 deletions.
7 changes: 4 additions & 3 deletions src/Assetic/Asset/FileAsset.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace October\Rain\Assetic\Asset;

use File;
use October\Rain\Assetic\Filter\FilterInterface;
use October\Rain\Assetic\Util\VarUtils;
use InvalidArgumentException;
Expand Down Expand Up @@ -36,7 +37,7 @@ public function __construct($source, $filters = [], $sourceRoot = null, $sourceP
$sourcePath = basename($source);
}
}
elseif (null === $sourcePath) {
elseif ($sourcePath === null) {
if (strpos($source, $sourceRoot) !== 0) {
throw new InvalidArgumentException(sprintf('The source "%s" is not in the root directory "%s"', $source, $sourceRoot));
}
Expand All @@ -57,7 +58,7 @@ public function load(FilterInterface $additionalFilter = null)
$source = VarUtils::resolve($this->source, $this->getVars(), $this->getValues());

if (!is_file($source)) {
throw new RuntimeException(sprintf('The source file "%s" does not exist.', $source));
throw new RuntimeException(sprintf('The source file "%s" does not exist.', File::nicePath($source)));
}

$this->doLoad(file_get_contents($source), $additionalFilter);
Expand All @@ -71,7 +72,7 @@ public function getLastModified()
$source = VarUtils::resolve($this->source, $this->getVars(), $this->getValues());

if (!is_file($source)) {
throw new RuntimeException(sprintf('The source file "%s" does not exist.', $source));
throw new RuntimeException(sprintf('The source file "%s" does not exist.', File::nicePath($source)));
}

return filemtime($source);
Expand Down
12 changes: 7 additions & 5 deletions src/Assetic/Combiner.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php namespace October\Rain\Assetic;

use File;
use October\Rain\Assetic\Asset\FileAsset;
use October\Rain\Assetic\Asset\AssetCache;
use October\Rain\Assetic\Asset\AssetCollection;
use October\Rain\Assetic\Cache\FilesystemCache;
use File;

/**
* Combiner helper class
Expand Down Expand Up @@ -64,15 +64,17 @@ public function prepareCombiner(array $assets, $options = [])
$filesSalt = null;
foreach ($assets as $asset) {
$filters = $this->getFilters(File::extension($asset), $production);
$path = file_exists($asset)
? $asset
: (File::symbolizePath($asset, null) ?: $this->localPath . $asset);

$path = File::symbolizePath($asset);
if (!file_exists($path) && file_exists($this->localPath . $asset)) {
$path = $this->localPath . $asset;
}

$files[] = new FileAsset($path, $filters, base_path());
$filesSalt .= $this->localPath . $asset;
}
$filesSalt = md5($filesSalt);

$filesSalt = md5($filesSalt);
$collection = new AssetCollection($files, [], $filesSalt);
$collection->setTargetPath($targetPath);

Expand Down
8 changes: 4 additions & 4 deletions src/Assetic/Factory/AssetFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function generateAssetName($inputs, $filters, $options = [])
public function getLastModified(AssetInterface $asset)
{
$mtime = 0;
foreach ($asset instanceof AssetCollectionInterface ? $asset : array($asset) as $leaf) {
foreach ($asset instanceof AssetCollectionInterface ? $asset : [$asset] as $leaf) {
$mtime = max($mtime, $leaf->getLastModified());

if (!$filters = $leaf->getFilters()) {
Expand All @@ -272,7 +272,7 @@ public function getLastModified(AssetInterface $asset)
continue;
}

// extract children from leaf after running all preceeding filters
// Extract children from leaf after running all preceding filters
$clone = clone $leaf;
$clone->clearFilters();
foreach (array_slice($prevFilters, 0, -1) as $prevFilter) {
Expand All @@ -298,7 +298,7 @@ public function getLastModified(AssetInterface $asset)
* * A glob: If the string contains a "*" it will be interpreted as a glob
* * A path: Otherwise the string is interpreted as a filesystem path
*
* Both globs and paths will be absolutized using the current root directory.
* Both globs and paths will be absolute using the current root directory.
*
* @param string $input An input string
* @param array $options An array of options
Expand Down Expand Up @@ -384,7 +384,7 @@ private static function isAbsolutePath($path)
}

/**
* Loops through the root directories and returns the first match.
* findRootDir loops through the root directories and returns the first match.
*
* @param string $path An absolute path
* @param array $roots An array of root directories
Expand Down
13 changes: 10 additions & 3 deletions src/Assetic/Traits/HasDeepHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ public function getDeepHashFromAssets($assets)
{
$key = '';

$assetFiles = array_map(function ($file) {
return file_exists($file) ? $file : (File::symbolizePath($file, null) ?: $this->localPath . $file);
}, $assets);
$assetFiles = [];
foreach ($assets as $file) {
$path = File::symbolizePath($file);
if (file_exists($path)) {
$assetFiles[] = $path;
}
elseif (file_exists($this->localPath . $path)) {
$assetFiles[] = $this->localPath . $path;
}
}

foreach ($assetFiles as $file) {
$filters = $this->getFilters(File::extension($file));
Expand Down
4 changes: 2 additions & 2 deletions src/Config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Modules and plugins can have config files in the /config directory. Plugin and m

````
// Get a configuration string from the CMS module
echo Config::get('cms::options.allowComments');
echo Config::get('cms::options.allow_comments');
// Get a configuration string from the october/blog plugin.
echo Config::get('october.blog::options.allowComments');
echo Config::get('october.blog::options.allow_comments');
````

## Overriding configuration strings
Expand Down
73 changes: 72 additions & 1 deletion src/Database/Connections/MySqlConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,84 @@
use Illuminate\Database\Schema\MySqlBuilder;
use Illuminate\Database\Schema\MySqlSchemaState;
use Illuminate\Filesystem\Filesystem;
use Exception;
use PDO;

/**
* MySqlConnection
*/
class MySqlConnection extends Connection
{
/**
* The last inserted ID generated by the server
*
* @var string|int|null
*/
protected $lastInsertId;

/**
* Run an insert statement against the database.
*
* @param string $query
* @param array $bindings
* @param string|null $sequence
* @return bool
*/
public function insert($query, $bindings = [], $sequence = null)
{
return $this->run($query, $bindings, function ($query, $bindings) use ($sequence) {
if ($this->pretending()) {
return true;
}

$statement = $this->getPdo()->prepare($query);

$this->bindValues($statement, $this->prepareBindings($bindings));

$this->recordsHaveBeenModified();

$result = $statement->execute();

$this->lastInsertId = $this->getPdo()->lastInsertId($sequence);

return $result;
});
}

/**
* Get the last insert ID.
*
* @return int
*/
public function getLastInsertId()
{
return $this->lastInsertId;
}

/**
* Escape a binary value for safe SQL embedding.
*
* @param string $value
* @return string
*/
protected function escapeBinary($value)
{
$hex = bin2hex($value);

return "x'{$hex}'";
}

/**
* Determine if the given database exception was caused by a unique constraint violation.
*
* @param \Exception $exception
* @return bool
*/
protected function isUniqueConstraintError(Exception $exception)
{
return boolval(preg_match('#Integrity constraint violation: 1062#i', $exception->getMessage()));
}

/**
* Determine if the connected database is a MariaDB database.
*
Expand All @@ -35,7 +106,7 @@ protected function getDefaultQueryGrammar()
if (method_exists($grammar, 'setConnection')) {
$grammar->setConnection($this);
}

return $this->withTablePrefix($grammar);
}

Expand Down
8 changes: 2 additions & 6 deletions src/Database/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,10 @@ public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'p
*/
public function newPivot(array $attributes = [], $exists = false)
{
/*
* October looks to the relationship parent
*/
// October looks to the relationship parent
$pivot = $this->parent->newRelationPivot($this->relationName, $this->parent, $attributes, $this->table, $exists);

/*
* Laravel looks to the related model
*/
// Laravel looks to the related model
if (empty($pivot)) {
$pivot = $this->related->newPivot($this->parent, $attributes, $this->table, $exists, $this->using);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Database/Relations/DefinedConstraints.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public function addDefinedConstraintsToRelation($relation, array $args = null)
$relation->withPivot($pivotData);
}

// Pivot incrementing key (belongsToMany, morphToMany, morphByMany)
if ($pivotKey = array_get($args, 'pivotKey')) {
$relation->withPivot($pivotKey);
}

// Pivot timestamps (belongsToMany, morphToMany, morphByMany)
if (array_get($args, 'timestamps')) {
$relation->withTimestamps();
Expand Down
20 changes: 10 additions & 10 deletions src/Database/Scopes/MultisiteScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public function apply(BuilderBase $builder, ModelBase $model)
}
}

/**
* extend the Eloquent query builder.
*/
public function extend(BuilderBase $builder)
{
foreach ($this->extensions as $extension) {
$this->{"add{$extension}"}($builder);
}
}

/**
* addWithSite removes this scope and includes the specified site
*/
Expand Down Expand Up @@ -67,14 +77,4 @@ protected function addWithSyncSites(BuilderBase $builder)
return $builder->withSites($builder->getModel()->getMultisiteSyncSites());
});
}

/**
* extend the Eloquent query builder.
*/
public function extend(BuilderBase $builder)
{
foreach ($this->extensions as $extension) {
$this->{"add{$extension}"}($builder);
}
}
}
24 changes: 24 additions & 0 deletions src/Database/Scopes/SoftDeleteScope.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php namespace October\Rain\Database\Scopes;

use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Database\Eloquent\Model as ModelBase;
use Illuminate\Database\Eloquent\Builder as BuilderBase;

/**
* SoftDeleteScope
*
* @package october\database
* @author Alexey Bobkov, Samuel Georges
*/
class SoftDeleteScope extends SoftDeletingScope
{
/**
* apply the scope to a given Eloquent query builder.
*/
public function apply(BuilderBase $builder, ModelBase $model)
{
if ($model->isSoftDeleteEnabled()) {
$builder->whereNull($model->getQualifiedDeletedAtColumn());
}
}
}
26 changes: 18 additions & 8 deletions src/Database/Traits/SoftDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Illuminate\Database\Eloquent\Model as EloquentModel;
use Illuminate\Database\Eloquent\Collection as CollectionBase;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use October\Rain\Database\Scopes\SoftDeleteScope;

/**
* SoftDelete trait for flagging models as deleted instead of actually deleting them.
Expand All @@ -22,7 +22,7 @@ trait SoftDelete
*/
public static function bootSoftDelete()
{
static::addGlobalScope(new SoftDeletingScope);
static::addGlobalScope(new SoftDeleteScope);

static::softDeleted(function($model) {
/**
Expand Down Expand Up @@ -106,17 +106,18 @@ public function forceDelete()
*/
protected function performDeleteOnModel()
{
if ($this->forceDeleting) {
if ($this->forceDeleting || !$this->isSoftDeleteEnabled()) {
$this->performDeleteOnRelations();

$this->setKeysForSaveQuery($this->newQuery()->withTrashed())->forceDelete();

$this->exists = false;
}
else {
$this->performSoftDeleteOnRelations();

$this->performSoftDeleteOnRelations();

$this->runSoftDelete();
$this->runSoftDelete();
}
}

/**
Expand Down Expand Up @@ -248,7 +249,7 @@ public function trashed()
*/
public static function withTrashed()
{
return with(new static)->newQueryWithoutScope(new SoftDeletingScope);
return with(new static)->newQueryWithoutScope(new SoftDeleteScope);
}

/**
Expand All @@ -261,7 +262,7 @@ public static function onlyTrashed()

$column = $instance->getQualifiedDeletedAtColumn();

return $instance->newQueryWithoutScope(new SoftDeletingScope)->whereNotNull($column);
return $instance->newQueryWithoutScope(new SoftDeleteScope)->whereNotNull($column);
}

/**
Expand Down Expand Up @@ -294,6 +295,15 @@ public static function restored($callback)
static::registerModelEvent('restored', $callback);
}

/**
* isSoftDeleteEnabled allows for programmatic toggling
* @return bool
*/
public function isSoftDeleteEnabled()
{
return true;
}

/**
* getDeletedAtColumn gets the name of the "deleted at" column.
* @return string
Expand Down
Loading

0 comments on commit cbd822a

Please sign in to comment.