October CMS issue with file attachment during tests - laravel

I am using October CMS
I have a model which has some attachOne and attachMany file attachments.
Both of these work fine during normal use.
However I am having difficulty with setting up tests
I have the following code in my test class
$logo = file(__DIR__ . '/assests/images/logo.png');
$file = new System\Models\File;
$file->data = __DIR__ . '/assests/images/Sample-Photo.jpeg';
$file->is_public = 1;
$file->save();
$nhd->developer_logo = (new System\Models\File)->fromData($logo, 'logo.png');
$nhd->development_photos->add($file);
$nhd->save();
$developer_logo_path = $nhd->developer_logo->getPath();
$photo_path = $nhd->development_photos[0]->getPath();
Both the ‘$developer_logo_path’ and ‘$photo_path’ variables successfully return a stored file path ( which actually points to a file which has been saved ) which is what i would except.
However if i then let the test run and execute the normal code. If I put a breakpoint in the component php file at the point after the model referred to in the test code as $nhd has been loaded there is a ‘developer_logo’ attached ( the AttachOne file ) but there are no ‘development_photos’ ( the attachMany file ).
As a result the template also does not output anything when {{component.development_photos}} is used
I also tried using the inline method to add the attachMany file ( $nhd->development_photos = (new System\Models\File)->fromData($photo, ‘logo.png’); ) and this also did not work.
Can anyone help me?

Related

Delete file in Laravel using Google Drive API

I'm using this command to upload the file to Google Drive (store function in controller):
$request->anexo->storeAs('1tD*******************-6', $file_name, 'google');
And this to get the link:
$link = Storage::disk('google')->url('1tD*******************-6/' . $file_name);
This is working fine. But when i try to delete the file i can't find it in the destroy function in the same controller. I've tried the commands below and all of them return false:
$att = OrdemAttachment::findOrFail($id);
$link = Storage::disk('google')->url('1tD*******************-6/' . $att->file_name);
// dd($link);
$exists = Storage::disk('google')->has('1tD*******************-6/' . $att->file_name);
// dd($exists);
$delete = Storage::disk('google')->delete('1tD*******************-6/' . $att->file_name);
// dd($delete);
Is there another command that must be used instead of these?
I figured it out, I was trying to use the file name and even tried to use the google drive link. But what worked was using the file id (you can find the id inside the link). So, for example, if the link to the file is https://drive.google.com/uc?id=1AgF87s1lw9TSsRhVOpGNJ2K6wq3A8FzD&export=media, to delete the file in google drive with the id would go like this:
$delete = Storage::disk('google')->delete('1tD*******************-6/1AgF87s1lw9TSsRhVOpGNJ2K6wq3A8FzD');
1tD*******************-6 is the subfolder id and 1AgF87s1lw9TSsRhVOpGNJ2K6wq3A8FzD is the id of the file extracted from the link.

Get the file from directory

I'm trying to get all files from a directory and store it inside a variable the process is like When I upload a file,i store it inside a variable ,in this scenario the process will be same but i wont uploading anything , I will be directly sending those files ,
Any help would be much appreciated
This what I tried
$dir = public_path('dbf');
// $new_path = public_path('new_files');
$files1 = scandir($dir);
$count=count($files1);
for($i=1;$i<$count;$i++)
{
$file=$files1[$i];
if($files1[$i]!='.' && $files1[$i]!='..')
{
$data=file_get_contents($dir.'/'.$file);
$name=$data->getClientOriginalName;
echo $name;
}
}
Its showing me error
Trying to get property 'getClientOriginalName' of non-object
Please solve this for me
inside that folder there is a file named cams_transaction.dbf
content of that file

How do I export contents between xml tags based on names in Extendscript for Indesign?

All I'd like to do here is open an InDesign 2018 CC file, pull out text uniquely (here I've chosen to grab content inside XML tag called "Title" from named tag window in the InDesign application side), save it to a txt file, and close the InDesign doc. I'm working in the Extendscript app, using Adobe InDesign CC 2018 (13.064). I just need to push to a txt file only certain named data (textboxes, xmltags, pageitems, etc) the contents based on anything, but via the name of the data holder. But xmltags are the only objects that I can name in the InDesign app apart from layers, and layers won't work for other reasons. So I'm stuck not being able to refer to xml-tagged contents. Please help.
Note:
I get an error with this code saying "Title" isn't defined, and I understand the error, but not sure how to utilize the method XML.toString() without referring to an object that's named inside the InDesign file. So I guess I'm using the wrong method to refer to xml-tagged data already located in a file??
So naturally, I throw out XML.toString() and utilize the commented out code (below) "app.activeDocument.xmlItems.item;" thinking maybe I will get an array of all items that are xml tagged, which is not even specific enough for my goal, but I'm desperate, and I get another newer error regarding the "exportfile" line of code: myArticles.exportFile() is not a function.
My code so far:
app.open(File("C:/Users/Sean/Desktop/New folder/va tech 2.indd"), true);
myArticles = Title.toString();
//THIS ATTEMPT WON'T WORK EITHER AS RPLCMNT FOR LINE ABOVE: myArticles= app.activeDocument.xmlItems.item;
myArticles.exportFile(ExportFormat.textType, new File("/C/Users/Sean/Desktop/New folder/test.txt"), false);
app.documents.everyItem().close(SaveOptions.NO);
var main = function() {
var doc, root, xes, n, nXE, st, xc, strs = [],
f = File ( Folder.desktop+"/contents.txt" );
try {
//NEED TO CHANGE THE URL. Ex: some/url > /Users/user/Desktop/foo.indd
doc = app.open ( File ( "some/url" ) );
}
catch(err){
alert(err.message);
return;
}
if ( !doc ) {
alert("You need an open document" );
return;
}
root = doc.xmlElements[0];
xes = root.evaluateXPathExpression("//Title");
n = xes.length;
while ( n-- ) {
nXE = xes[n];
xc = nXE.xmlContent;
if ( xc instanceof Story ) {
strs.push( xc.contents );
}
}
if ( strs.length ) {
f.open('w');
f.write ( strs.reverse().join("\r") );
f.close();
}
}
var u;
app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "The Script" );

How to create wiki-family on MediaWiki-Vagrant?

Are there any roles to manage or create multiple wikis? I have checked Manual:Wiki family and understand the normal way of creating multiple wiki in a MediaWiki.
I'd like to share what I got in addition to the manual.
Beside of multiple domains/subdomain you can get also multiple path for multiple wikis. Each will stand with different configuration setup by adding the action path at the end line on each of your setting files as shown:
# End of automatically generated settings.
# Add more configuration options below.
$wgArticlePath = "/map/$1";
$actions = array( 'edit', 'watch', 'unwatch', 'delete','revert', 'rollback',
'protect', 'unprotect', 'markpatrolled', 'render', 'submit', 'history',
'purge', 'info' );
foreach ( $actions as $action ) {
$wgActionPaths[$action] = "$wgArticlePath/$action";
}
$wgActionPaths['view'] = "$wgArticlePath";
Change the map variable to your path on each of the setting files then place them under the folders named exactly follow to your path.
So you can modify the code in the LocalSettings.php similar as below:
<?php
// Include common settings to all wikis before this line (eg. database configuration)
$paths = explode('/' , $_SERVER['REQUEST_URI']);
if($paths[2] === NULL) {$path = 'map';} else {$path = $paths[1];}
switch ( $_SERVER['SERVER_NAME'] ) {
case 'wiki.tophyips.info':
require_once "settings/$path/tophyips.php";
break;
case 'wiki.hyipscript.info':
require_once "settings/$path/hyipscript.php";
break;
case 'wiki.hyipmonitors.info':
require_once "settings/$path/hyipmonitors.php";
break;
default:
header( 'HTTP/1.1 404 Not Found' );
echo 'This wiki is not available. Check configuration.';
exit( 0 );
}
Change the map variable on $path = 'map'; to one of your default path of your choice from all the paths you put on the setting files above.
You may check the result of the configuration above on my wiki family page.
The mediawiki::wiki module is used for creating wikis. Some roles that use it are commons and private (there are surely more). If you just want to create a wiki without any extra configuration, you can just write mediawiki::wiki{<wikiname>:} and put it in puppet/modules/role/manifests/my_role.pp (inside a role block - see other role files for the format) and then you can enable/disable via vagrant roles.

Does anyone know what is the 32 character string before the product image filename in Magento?

I ask this question, since I am trying to get the images I have just copied from Domain A to work in Domain B, (which is using the same database).
http://DOMAIN_A/magento/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/b/0/b0041-1.jpg
I think knowing what the 32 character string is, which help me find a good explanation why the images are not being found in the front or backend of Magento after reinstall on DOMAIN B.
RE: Magento version 1.4.0.1
Here's the code that creates that filename path, found in Mage_Catalog_Model_Product_Image:
// build new filename (most important params)
$path = array(
Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(),
'cache',
Mage::app()->getStore()->getId(),
$path[] = $this->getDestinationSubdir()
);
if((!empty($this->_width)) || (!empty($this->_height)))
$path[] = "{$this->_width}x{$this->_height}";
// add misk params as a hash
$miscParams = array(
($this->_keepAspectRatio ? '' : 'non') . 'proportional',
($this->_keepFrame ? '' : 'no') . 'frame',
($this->_keepTransparency ? '' : 'no') . 'transparency',
($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
$this->_rgbToString($this->_backgroundColor),
'angle' . $this->_angle,
'quality' . $this->_quality
);
// if has watermark add watermark params to hash
if ($this->getWatermarkFile()) {
$miscParams[] = $this->getWatermarkFile();
$miscParams[] = $this->getWatermarkImageOpacity();
$miscParams[] = $this->getWatermarkPosition();
$miscParams[] = $this->getWatermarkWidth();
$miscParams[] = $this->getWatermarkHeigth();
}
$path[] = md5(implode('_', $miscParams));
// append prepared filename
$this->_newFile = implode('/', $path) . $file; // the $file contains heading slash
So, the hash is generated from the configuration info (aspect ratio, etc), as well as the watermark info. This information will not usually change. However, I do see that the path is partially generated from the store_id of the current store, so your trouble may be there.
Is there a reason you can't let Magento use its normal caching procedures for both stores? Since Magento checks the filesystem for the cached image, there shouldn't be a conflict.
Hope that helps!
Thanks,
Joe
Upon contemplation, are you just trying to get the catalog images to work in both domains? The non-cached version of the catalog images are at %magento%/media/catalog/product. Copy the directories from that location and your catalog images should work.
Moving over the cached images isn't going to go far, since they will be deleted next time you flush the Magento cache. So, having moved the images that are in /media/catalog/product, flush the Magento image cache. Make sure that the file permissions are correct for reading. Then, head into Mage_Catalog_Model_Product_Image and take a look at the following code (approx line 270):
if ($file) {
// add these for debugging
Mage::log($baseDir.$file);
Mage::log(file_exists($baseDir.$file));
Mage::log($this->checkMemory($baseDir.$file));
if ((!file_exists($baseDir . $file)) || !$this->_checkMemory($baseDir . $file)) {
$file = null;
}
}
Add a var_dump or Mage::log statement in there (depending on whether you have logging enabled), and verify that the path to the images is correct, and that you have enough memory for the operation. This is the code that will choose the default image for you if no image path exists. If you still can't get it, post the output of those three logging statements and we'll keep trying. :)

Resources